|
15 | 15 | using System.Threading.Tasks;
|
16 | 16 | using Windows.ApplicationModel.DataTransfer;
|
17 | 17 | using Windows.Foundation;
|
| 18 | +using Windows.Graphics.Imaging; |
18 | 19 | using Windows.Storage;
|
19 | 20 | using Windows.Storage.Pickers;
|
20 | 21 | using Windows.Storage.Streams;
|
@@ -471,18 +472,20 @@ private async void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
|
471 | 472 | {
|
472 | 473 | RandomAccessStreamReference pastedBitmap = await dataPackageView.GetBitmapAsync();
|
473 | 474 | var pastedBitmapStream = await pastedBitmap.OpenReadAsync();
|
474 |
| - StorageFile tmpFile = await StorageFile.CreateStreamedFileAsync("Signal-Windows-tmpbitmap.bmp", async (fileStream) => |
| 475 | + var tmpFile = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Signal-Windows-Screenshot.png", CreationCollisionOption.GenerateUniqueName); |
| 476 | + using (var tmpFileStream = await tmpFile.OpenAsync(FileAccessMode.ReadWrite)) |
475 | 477 | {
|
476 |
| - byte[] buffer = new byte[8192]; |
477 |
| - var read = await pastedBitmapStream.ReadAsync(buffer.AsBuffer(), (uint) buffer.Length, InputStreamOptions.None); |
478 |
| - while (read.Length > 0) |
479 |
| - { |
480 |
| - await fileStream.WriteAsync(read); |
481 |
| - read = await pastedBitmapStream.ReadAsync(buffer.AsBuffer(), (uint) buffer.Length, InputStreamOptions.None); |
482 |
| - } |
483 |
| - await fileStream.FlushAsync(); |
484 |
| - fileStream.Dispose(); |
485 |
| - }, null); |
| 478 | + BitmapDecoder decoder = await BitmapDecoder.CreateAsync(pastedBitmapStream); |
| 479 | + var pixels = await decoder.GetPixelDataAsync(); |
| 480 | + BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, tmpFileStream); |
| 481 | + encoder.SetPixelData(decoder.BitmapPixelFormat, |
| 482 | + BitmapAlphaMode.Ignore, // Alpha is not used |
| 483 | + decoder.OrientedPixelWidth, |
| 484 | + decoder.OrientedPixelHeight, |
| 485 | + decoder.DpiX, decoder.DpiY, |
| 486 | + pixels.DetachPixelData()); |
| 487 | + await encoder.FlushAsync(); |
| 488 | + } |
486 | 489 | SelectedFile = tmpFile;
|
487 | 490 | AddedAttachmentDisplay.ShowAttachment(SelectedFile.Name);
|
488 | 491 | UpdateSendButtonIcon();
|
|
0 commit comments