How to save WriteableBitmap Image to Storage File in Windows Phone 8.1 RT/Windows 10?
To convert a WriteableBitmap to Storage File first you need to Encode the Image in the right way so that it won't turn out to be a blank image.

- StorageFile filePath = await WriteableBitmapToStorageFile(wb, FileFormat.Jpeg);

- private async Task < StorageFile > WriteableBitmapToStorageFile(WriteableBitmap WB, FileFormat fileFormat)
- {
- string FileName = "YourFile.";
- Guid BitmapEncoderGuid = BitmapEncoder.JpegEncoderId;
- switch (fileFormat)
- {
- case FileFormat.Jpeg:
- FileName += "jpeg";
- BitmapEncoderGuid = BitmapEncoder.JpegEncoderId;
- break;
- case FileFormat.Png:
- FileName += "png";
- BitmapEncoderGuid = BitmapEncoder.PngEncoderId;
- break;
- case FileFormat.Bmp:
- FileName += "bmp";
- BitmapEncoderGuid = BitmapEncoder.BmpEncoderId;
- break;
- case FileFormat.Tiff:
- FileName += "tiff";
- BitmapEncoderGuid = BitmapEncoder.TiffEncoderId;
- break;
- case FileFormat.Gif:
- FileName += "gif";
- BitmapEncoderGuid = BitmapEncoder.GifEncoderId;
- break;
- }
- var file = await Windows.Storage.ApplicationData.Current.TemporaryFolder.CreateFileAsync(FileName, CreationCollisionOption.GenerateUniqueName);
- using(IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
- {
- BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoderGuid, stream);
- Stream pixelStream = WB.PixelBuffer.AsStream();
- byte[] pixels = new byte[pixelStream.Length];
- await pixelStream.ReadAsync(pixels, 0, pixels.Length);
- encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint) WB.PixelWidth, (uint) WB.PixelHeight,
- 96.0,
- 96.0,
- pixels);
- await encoder.FlushAsync();
- }
- return file;
- }
- private enum FileFormat
- {
- Jpeg,
- Png,
- Bmp,
- Tiff,
- Gif
- }
- // Get a photo as a Bitmap Image using storage file path.
- BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));
- Myimage.Source=bmpImage ;
- <Image x:Name="MyImage" strech="Uniform"/>

Agu PerezPosted Mar 28, 2016, 6:33 PM
Hi man, nice post. I'm using your code to resize an existing image (sd card) but when the image is saved it is shown blank. Do you know what am I doing wrong? Thanks
Santhakumar MunuswamyPosted Nov 16, 2015, 11:42 PM
Nice share