This project is read-only.

Converting GIF/PNG to JPG

Jan 21, 2011 at 9:22 AM

Hi everyone,

Could anyone please tell me which would be the preferred way of converting GIF and PNG images to JPG using ImageTools ? The GIF's and PNG's are already retrieved from a server, and i'd like to save them locally on the Windows Phone 7 picture library, however the API method for this only allows JPG images to be saved, thus the need for conversion. I think perhaps that converting first the GIF/PNG to raw bitmaps (if it's even possible) and then to JPG might work, however it sounds a bit slow; is there any faster, more efficient way ? Unfortunately the documentation didn't make this topic clear to me.


Thanks in advance,


Jan 24, 2011 at 12:10 PM
Edited Jan 24, 2011 at 12:11 PM

I am currently using the following code to convert from PNGs to JPGs:

private byte[] ConvertImageToJpg(byte[] imageContent) // for some reason i have to work directly with array of bytes
            JpegEncoder jpegEncoder = new JpegEncoder();
            BitmapImage bm = new BitmapImage();
            bm.SetSource(new MemoryStream(imageContent));
            WriteableBitmap wbm = new WriteableBitmap(bm);            

            MemoryStream encodedStream = new MemoryStream();
            jpegEncoder.Quality = 80;
            jpegEncoder.Encode(wbm.ToImage(), encodedStream); // takes a very, very long time for some higher-res PNGs (+10 sec)
            return encodedStream.ReadToEnd(); //ReadToEnd() is an extension method for reading a stream into a byte[]

Could anyone please suggest if there is any efficiency enhancement that could be applied here in order to significantly reduce the encoding time ?


Jan 8, 2014 at 6:56 AM
You target is having a conversion from image to image without any external document processing, so, it will be much easier. Here is my recommendation of an image converter to be applied to significantly reduce the encoding time. The image forms which are supported by the image converter are jpeg, png, bmp, gif, jpeg and tiff, and even jbig2.
Mar 5, 2014 at 9:26 AM
Hey, perhaps you can try this lib I'm using to freely convert between different image formats, like png, jpeg, gif, etc. :). And save to local files as well. :)
Apr 15, 2014 at 5:07 AM