我正在尝试share an Image
通过Share charm
,但在魅力 ' Mail
' 应用程序中不可用,因此无法通过邮件共享图像。但我试图通过Native Photo app
& thereMail
选项共享相同的图像。
在我的代码下面
private async void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataRequestDeferral deferral = e.Request.GetDeferral();
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Image";
IRandomAccessStream stream = new InMemoryRandomAccessStream();
Guid encoderId;
switch (file.FileType)
{
case ".png":
encoderId = BitmapEncoder.PngEncoderId;
break;
case ".jpg":
case ".jpeg":
default:
encoderId = BitmapEncoder.JpegEncoderId;
break;
}
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(encoderId, stream);
Stream pixelStream = image.PixelBuffer.AsStream();
byte[] 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);
requestData.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));
await encoder.FlushAsync();
deferral.Complete();
}
我错过了我的代码中的任何内容吗?
- - - - - - - - - - - - - - - - - - -编辑 - - - - -
有替代方案;看到这个这个链接