Created
September 17, 2015 12:37
-
-
Save kiichi/a46fd9c639b0cf810b8e to your computer and use it in GitHub Desktop.
Use WritableBitmapEx package in Windows Universal App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Download WritableBitmapEx Package from NuGet | |
| FileOpenPicker openPicker = new FileOpenPicker(); | |
| openPicker.ViewMode = PickerViewMode.Thumbnail; | |
| openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; | |
| openPicker.FileTypeFilter.Add(".png"); | |
| StorageFile file = await openPicker.PickSingleFileAsync(); | |
| if (file != null) { | |
| var fileStream = await file.OpenAsync(FileAccessMode.Read); | |
| WriteableBitmap wbmp = await BitmapFactory.New(1, 1).FromStream(fileStream); | |
| wbmp = wbmp.Resize(600, 600, WriteableBitmapExtensions.Interpolation.Bilinear); | |
| FileSavePicker savePicker = new FileSavePicker(); | |
| savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; | |
| savePicker.FileTypeChoices.Add("PNG File", new List<string>() { ".png" }); | |
| savePicker.SuggestedFileName = "New Photo"; | |
| StorageFile fileDst = await savePicker.PickSaveFileAsync(); | |
| using (var fs = await fileDst.OpenAsync(FileAccessMode.ReadWrite)) { | |
| await wbmp.ToStream(fs, BitmapEncoder.PngEncoderId); | |
| await fs.FlushAsync(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment