Storing images in windows phone 8

871 views Asked by At

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. ImageTools has PNG encoder and decoder. But I really cant find examples to use them.

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.

For storing

        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();
            }         

        }

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?

I have checked out this, this , this and lot more like this. I'm developing app for WP8

1

There are 1 answers

0
alfah On

I have used the PNG Writer Library found in ToolStack and it works :)