---
title: "Saving Bitmap as PNG on WP7"  
description: "Saving Bitmap as PNG on WP7"  
author: "Royce Roy"  
published: 2015-04-25  
updated: 2015-04-25  
canonical: https://www.mindstick.com/forum/23141/saving-bitmap-as-png-on-wp7  
category: "windows phone"  
tags: ["c#", "windows phone"]  
reading_time: 2 minutes  

---

# Saving Bitmap as PNG on WP7

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to save a [bitmap](https://www.mindstick.com/forum/1924/find-image-format-using-bitmap-object-in-c-sharp) to my isolated [storage](https://www.mindstick.com/articles/44536/finding-your-self-storage-facility) as a png [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp). I found a [library](https://www.mindstick.com/forum/34615/software-framework-vs-library) on Codeplex called ImageTools which [people](https://www.mindstick.com/news/2295/more-people-need-to-monitor-this-crucial-metric-for-heart-health) have been recommending but when i try it and attempt to open the file it says that its corrupt. Any know what i am [doing wrong](https://answers.mindstick.com/qa/36736/what-are-indians-doing-wrong-on-whatsapp)?\

```
private static void SaveImageToIsolatedStorageAsPng(BitmapImage bitmap, string fileName){    //convert to memory stream    MemoryStream memoryStream = new MemoryStream();    WriteableBitmap writableBitmap = new WriteableBitmap(bitmap);    writableBitmap.SaveJpeg(memoryStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);    //encode memory stream as PNG    ExtendedImage image = new ExtendedImage();    image.SetSource(memoryStream);    PngEncoder encoder = new PngEncoder();    //Save to IsolatedStorage    using (var store = IsolatedStorageFile.GetUserStoreForApplication())    using (var writeStream = new IsolatedStorageFileStream(fileName, FileMode.Create, store))    {        encoder.Encode(image, writeStream);    }}
```

## Replies

### Reply by Anonymous User

You're attempting to convert the JPEG memory stream into PNG. That will make it corrupt - you should save the Bitmap directly to PNG.\
I haven't tried this particular task with the imagetools library, but if you see John Papa's blog, it looks like you need to call the ToImage extension method on your WriteableBitmap which is provided as part of ImageTools. Then you can use the encoder to take this image and write out to your open stream.

```
var img = bitmap.ToImage();var encoder = new PngEncoder();using (var stream = new IsolatedStorageFileStream(fileName, FileMode.Create, store)){    encoder.Encode(img, stream);    stream.Close();}
```


---

Original Source: https://www.mindstick.com/forum/23141/saving-bitmap-as-png-on-wp7

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
