在Windows Phone 8.1中共享渲染到位图图像

 盲人一块 发布于 2023-01-02 10:36

我想在Windows Phone 8.1中将我的画布分享为图像.为此我首先将我的画布转换为图像然后共享它.我尝试了我的Windows 8.1代码.没有出现错误但图像不在共享源应用程序中只有说明和标题出现.

这是代码:

private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
        {
            e.Request.Data.Properties.Title = "My app";
            e.Request.Data.Properties.Description = "app description";

            DataRequest request = e.Request;

            // Request deferral to wait for async calls
            DataRequestDeferral deferral = request.GetDeferral();

            // XAML objects can only be accessed on the UI thread, and the call may come in on a background thread
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                try
                {

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

                    // Encode image to an in-memory stream
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);

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

                    await encoder.FlushAsync();


                    request.Data.Properties.Thumbnail = RandomAccessStreamReference.CreateFromStream(stream);

                    //  e.Request.Data.Properties.Thumbnail=(RandomAccessStreamReference.CreateFromStream(stream));
                    // Set content of the DataProviderRequest to the encoded image in memory
                    request.Data.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));
                }
                finally
                {
                    deferral.Complete();

                }
            });

        }

在此输入图像描述

在此输入图像描述

这在Windows 8.1中运行良好,我认为它也应该在这里工作正常.图像在消息,OneNote等共享应用程序时看不到.

需要帮助.谢谢.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有