Skip to content

Instantly share code, notes, and snippets.

@kiichi
Created September 17, 2015 12:37
Show Gist options
  • Select an option

  • Save kiichi/a46fd9c639b0cf810b8e to your computer and use it in GitHub Desktop.

Select an option

Save kiichi/a46fd9c639b0cf810b8e to your computer and use it in GitHub Desktop.
Use WritableBitmapEx package in Windows Universal App
// 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