BeFriend.Services.SpineClass.ImagetoIsolatedStorageSaver C# (CSharp) Метод

ImagetoIsolatedStorageSaver() публичный статический Метод

public static ImagetoIsolatedStorageSaver ( IRandomAccessStreamWithContentType stream, string filename ) : void
stream IRandomAccessStreamWithContentType
filename string
Результат void
        public static async void ImagetoIsolatedStorageSaver(IRandomAccessStreamWithContentType stream, string filename)
        {
            try
            {
                //WriteableBitmap is used to save our image to our desired location, which in this case is the LocalStorage of app
                var image = new WriteableBitmap(50, 50);
                image.SetSource(stream);

                //Saving to roaming folder so that it can sync the profile pic to other devices
                var saveAsTarget =
                    await
                        ApplicationData.Current.RoamingFolder.CreateFileAsync(filename,
                            CreationCollisionOption.ReplaceExisting);

                //Encoding with Bitmap Encoder to jpeg format
                var encoder = await BitmapEncoder.CreateAsync(
                    BitmapEncoder.JpegEncoderId,
                    await saveAsTarget.OpenAsync(FileAccessMode.ReadWrite));
                //Saving as a stream
                var pixelStream = image.PixelBuffer.AsStream();
                var pixels = new byte[pixelStream.Length];
                await pixelStream.ReadAsync(pixels, 0, pixels.Length);
                encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint) image.PixelWidth,
                    (uint) image.PixelHeight, 96.0, 96.0, pixels);
                await encoder.FlushAsync();
                await pixelStream.FlushAsync();
                pixelStream.Dispose();
                
            }
            catch (Exception e)
            {
                Debug.Write(e);
            }
        }