Convert PNG to JPG Windows Phone

350 Views Asked by At

i have a PNG file and i would convert into JPG The PNG is a large size(high resolution) (for example 30/40MB)

if i use this code receive a memory leak

using (var fileStream = myIsolatedStorage.OpenFile("1.png",FileMode.Open,FileAccess.Read))
{
    WriteableBitmap wb = PictureDecoder.DecodeJpeg(fileStream);
}

How to? Thanks

1

There are 1 best solutions below

2
On

Your code cannot work since you loaded a png file, but the method beneath accepts jpeg stream. You can do the following>

  1. Open the png file with OpenFile
  2. Load the file into a BitmapImage
  3. Create a WriteableBitmap from that BitmapImage
  4. Save the created WriteableBitmap as a jpeg file using the SaveJpeg extension method.