To save and retrieve image file from a stream to local storage in Windows Phone 8.1 Runtime Apps, firstly you need to set the stream to WritableBitmapImage like the following:
- var wbm = new WriteableBitmap(600, 800);
- await wbm.SetSourceAsync(stream);
- StorageFolder folder = ApplicationData.Current.LocalFolder;
- if (folder != null)
- {
- StorageFile file = await folder.CreateFileAsync("imagefile" + ".jpg", CreationCollisionOption.ReplaceExisting);
- using(var storageStream = await file.OpenAsync(FileAccessMode.ReadWrite))
- {
- var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, storageStream);
- var pixelStream = wbm.PixelBuffer.AsStream();
- var pixels = new byte[pixelStream.Length];
- await pixelStream.ReadAsync(pixels, 0, pixels.Length);
- encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint) wbm.PixelWidth, (uint) wbm.PixelHeight, 48, 48, pixels);
- await encoder.FlushAsync();
- }
- }
- string fileName = "imagefile.jpg";
- StorageFolder myfolder = ApplicationData.Current.LocalFolder;
- BitmapImage bitmapImage = new BitmapImage();
- StorageFile file = await myfolder.GetFileAsync(fileName);
- var image = await Windows.Storage.FileIO.ReadBufferAsync(file);
- Uri uri = new Uri(file.Path);
- BitmapImage img = new BitmapImage(new Uri(file.Path));
- myimage.Source = img;
- <Image x:Name="myimage" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Top"/>

Surajit BeraPosted Nov 6, 2018, 1:00 AM
Please help me
Surajit BeraPosted Nov 6, 2018, 1:00 AM
What you namespace for this?
Adnan SiddiqPosted Nov 25, 2015, 7:44 AM
await wbm.SetSourceAsync(stream); how get stream object from wbm.?
Saineshwar BageriPosted Sep 13, 2015, 11:54 PM
Good One