title: Storing images in windows phone 8
body: <p>I have been really cracking my head trying to write and read png files into a folder in Windows Phone 8. From few blogs sites and codeplex i found that the there is an extension to the WritableBitmap Class which provides few extra functionalities. <a href="http://imagetools.codeplex.com/" rel="nofollow noreferrer">ImageTools</a> has PNG encoder and decoder. But I really cant find examples to use them. </p>
  
  <p>What Im trying to achieve here is to create a folder called page and then in it a file called Ink File. I want to convert the bitmap to a PNG and store it there. The bitmap is created from the strokes drawn on a canvas. The class ImageTools provides a function called ToImage to convert the strokes from the canvas to image.</p>
  
  <p>For storing</p>
  
  <pre class="lang-cs prettyprint-override"><code>        ExtendedImage myImage = InkCanvas.ToImage();
  
          var encoder = new PngEncoder();
  
          var dataFolder = await local.CreateFolderAsync("Page", CreationCollisionOption.OpenIfExists);
  
          StorageFile Ink_File = await dataFolder.CreateFileAsync("InkFile", CreationCollisionOption.ReplaceExisting);
  
          using (var stream = await Ink_File.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
          {
              using (var s = await Ink_File.OpenStreamForWriteAsync())
              {
                  encoder.Encode(myImage, s);
                  await s.FlushAsync();
                  s.Close();
              }         
  
          }
  </code></pre>
  
  <p>Is this a correct method? I receive some null exceptions for this. How do i find if the image is saved as png. How is this image saved? Is it encoded and saved in a file or is it saved as a png itsef. And how do we read this back? </p>
  
  <p>I have checked out <a href="https://stackoverflow.com/questions/14434951/saving-writeablebitmap-to-png">this</a>, <a href="http://imagetools.codeplex.com/wikipage?title=Write%20the%20content%20of%20a%20canvas%20to%20a%20file" rel="nofollow noreferrer">this</a> , <a href="https://stackoverflow.com/questions/7378946/saving-bitmap-as-png-on-wp7">this</a> and lot more like this.
  I'm developing app for WP8</p>