0

I need to write a method to turn the byte[] to .jpeg file and then zip these jpeg files.

I did some research but still couldnt figure it out. Thank you for your help.

code updated

Using Ionic.Zip;
public static void ZipJpeg(int ID)
{
    ZipFile zip = new ZipFile();
    Dictionary<int, byte[]> photos = new Dictionary<int, byte[]>();
    photos = clientInfo_BL.GetByID(ID);
    string fileName;
    foreach(var p in photos.Values)
    {
        fileName = p.uploadDate.toString() + ".jpeg";
        using(Image image = image.FromStream(new MemoryStream(p.ImageData)))
        {
             image.Save(fileName. ImageFormat.Jpeg);
        }
        Zip.AddEntry(image); // couldnt figure out this one
    }
    zip.save()//not sure if this one is right
    return zip;
}
Community
  • 1
  • 1
myname
  • 39
  • 5
  • 3
    start by searching for one step then the other. – DLeh Oct 20 '15 at 19:25
  • what is inside byte[]? also sure your code does not work. there is no magic.take a look at here http://stackoverflow.com/questions/8946846/converting-a-byte-array-to-png-jpg also to zip files just google it. http://stackoverflow.com/questions/940582/how-do-i-zip-a-file-in-c-using-no-3rd-party-apis – M.kazem Akhgary Oct 20 '15 at 19:26
  • Thank you for your helps. The posts online about zip file I have read were mostly using the file system to zip the files, which are not what I want. I wish to return the zip file with jpeg files to the user with out using the file system. – myname Oct 20 '15 at 19:53

1 Answers1

3

since you already have your byte array, you're just one step away from converting it to jpeg!

using(Image image = Image.FromStream(new MemoryStream(bitmap)))
{
    image.Save("output.jpg", ImageFormat.Jpeg);  
}

Image.FromStream()