private async void ExportImage(object sender, RoutedEventArgs e) { var picker = new FileSavePicker(); picker.FileTypeChoices.Add("png", new List <string> { ".png" }); picker.DefaultFileExtension = ".png"; StorageFile file = await picker.PickSaveFileAsync(); if (file != null) { var saveStream = await file.OpenStreamForWriteAsync(); var readStream = screen.GetStream(ImageFormat.Png, true); var data = new byte[readStream.Length]; readStream.Read(data, 0, (int)readStream.Length); saveStream.Write(data, 0, data.Length); saveStream.Dispose(); } }
private async void ExportImage(object sender, RoutedEventArgs e) { if (selection.Width == 0 || selection.Height == 0) { MessageDialog md = new MessageDialog(Strings.EmptySelectionMessage); md.ShowAsync(); return; } var picker = new FileSavePicker(); picker.FileTypeChoices.Add("png", new List <string> { ".png" }); picker.DefaultFileExtension = ".png"; StorageFile file = await picker.PickSaveFileAsync(); if (file != null) { var saveStream = await file.OpenStreamForWriteAsync(); var crop = new C1Bitmap((int)selection.Width, (int)selection.Height); crop.BeginUpdate(); for (int x = 0; x < selection.Width; ++x) { for (int y = 0; y < selection.Height; ++y) { crop.SetPixel(x, y, bitmap.GetPixel(x + (int)selection.X, y + (int)selection.Y)); } } crop.EndUpdate(); var readStream = crop.GetStream(ImageFormat.Png, true); var data = new byte[readStream.Length]; readStream.Read(data, 0, (int)readStream.Length); saveStream.Write(data, 0, data.Length); saveStream.Dispose(); } }