C# 使用共享魅力从windows应用商店应用程序共享图像

C# 使用共享魅力从windows应用商店应用程序共享图像,c#,xaml,winrt-xaml,windows-8.1,C#,Xaml,Winrt Xaml,Windows 8.1,我想在我的window store应用程序中将我的画布作为图像共享我正在使用此代码 if (DrawCanvas.Children.Count == 0) { MessageDialog dlg = new MessageDialog("Please add some content", "Warning"); dlg.ShowAsync(); return;

我想在我的window store应用程序中将我的画布作为图像共享我正在使用此代码

if (DrawCanvas.Children.Count == 0)
            {
                MessageDialog dlg = new MessageDialog("Please add some content", "Warning");
                dlg.ShowAsync(); 
                return;
            }

            // Render to an image at the current system scale and retrieve pixel contents
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(DrawCanvas);
            var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();

            var savePicker = new FileSavePicker();
            savePicker.DefaultFileExtension = ".png";
            savePicker.FileTypeChoices.Add(".png", new List<string> { ".png" });
            savePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            savePicker.SuggestedFileName = "snapshot.png";

            // Prompt the user to select a file
            var saveFile = await savePicker.PickSaveFileAsync();

            // Verify the user selected a file
            if (saveFile == null)
                return;

            // Encode the image to the selected file on disk
            using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);

                encoder.SetPixelData(
                    BitmapPixelFormat.Bgra8,
                    BitmapAlphaMode.Ignore,
                    (uint)renderTargetBitmap.PixelWidth,
                    (uint)renderTargetBitmap.PixelHeight,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    DisplayInformation.GetForCurrentView().LogicalDpi,
                    pixelBuffer.ToArray());

                await encoder.FlushAsync();
            }
if(DrawCanvas.Children.Count==0)
{
MessageDialog dlg=新建MessageDialog(“请添加一些内容”,“警告”);
dlg.showsync();
回来
}
//以当前系统比例渲染图像并检索像素内容
RenderTargetBitmap RenderTargetBitmap=新建RenderTargetBitmap();
等待renderTargetBitmap.RenderAsync(DrawCanvas);
var pixelBuffer=await renderTargetBitmap.GetPixelsAsync();
var savePicker=new FileSavePicker();
savePicker.DefaultFileExtension=“.png”;
savePicker.FileTypeChoices.Add(“.png”,新列表{.png});
savePicker.SuggestedStartLocation=PickerLocationId.PicturesLibrary;
savePicker.SuggestedFileName=“snapshot.png”;
//提示用户选择一个文件
var saveFile=await savePicker.PickSaveFileAsync();
//验证用户是否选择了一个文件
if(saveFile==null)
回来
//将图像编码到磁盘上的选定文件
使用(var fileStream=await saveFile.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder=await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId,fileStream);
编码器.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode。忽略,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
DisplayInformation.GetForCurrentView().LogicalDpi,
DisplayInformation.GetForCurrentView().LogicalDpi,
pixelBuffer.ToArray());
等待编码器。FlushAsync();
}
此代码正在将我的图像文件保存到我的磁盘上我想更改此代码以从我的应用程序共享此图像而不是保存到我的磁盘上,我如何才能实现这一点?
需要帮助。

我给你的建议是阅读这篇文章: