dommy - 2014-03-05

I am looking at using FreeImage with C# wrapper to reduce the size of my jpegs.

This is what I am trying to do.

I have a jpeg stored as a byte array in my client c# application. So:

     byte[] jpegData = null;
     Bitmap imageIn = new Bitmap(input);
     using (MemoryStream ms = new MemoryStream())
     {
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        imageIn.Dispose();
        jpegData = ms.ToArray();
     }

I then wish to convert it to jpeg2000 format. So I have this:

     using (MemoryStream ms2 = new MemoryStream(jpegData))
     {
         FIBITMAP myImage = new FIBITMAP();
         myImage = FreeImage.LoadFromStream(ms2);
         FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JP2, myImage, @"H:\testmotion\a\export2.jp2", FREE_IMAGE_SAVE_FLAGS.EXR_PXR24 | FREE_IMAGE_SAVE_FLAGS.EXR_LC);
     }

I would like to do 2 things here.

I wish to avoid this line:

FreeImage.Save(FREE_IMAGE_FORMAT.FIF_JP2, myImage, @"H:\testmotion\a\export2.jp2", FREE_IMAGE_SAVE_FLAGS.EXR_PXR24 | FREE_IMAGE_SAVE_FLAGS.EXR_LC);

and save it directly to a byte array.

Then after I have 'pushed' it to my web server I wish to save it back to the original jpeg.

The reason I want to save it to a jpeg on my server is becuase I need to render it into an img control using javascript.

The reason for encoding it to jpeg 2000 before 'pushing' it to my web server is to save on the amount of bytes transmitted over the internet.

Can this be done?