使用共享魅力从Windows商店应用程序共享图像

时间:2014-06-13 09:19:49

标签: c# xaml winrt-xaml windows-8.1

我想在我的窗口商店应用程序中将我的画布作为图像共享我正在使用此代码

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();
            }

此代码将我的图像文件保存到我的磁盘上我想更改此代码以从我的应用程序共享此图像而不是保存在我的磁盘上,我该如何实现? 需要帮助。

0 个答案:

没有答案