DataPackage.SetBitmap 在 Windows phone 8.1 WinRT 应用程序中不工作

DataPackage.SetBitmap is not working in Windows phone 8.1 WinRT App

我正在使用以下代码在我的 windows phone 8.1 应用程序中分享图像。

private async void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
    {
        var deferral = args.Request.GetDeferral();
        var bitmap = new RenderTargetBitmap();
        await bitmap.RenderAsync(this);

        // 1. Get the pixels
        IBuffer pixelBuffer = await bitmap.GetPixelsAsync();
        byte[] pixels = pixelBuffer.ToArray();

        // 2. Write the pixels to a InMemoryRandomAccessStream
        var stream = new InMemoryRandomAccessStream();
        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);

        encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight, 96, 96,
            pixels);

        await encoder.FlushAsync();
        stream.Seek(0);

        // 3. Share it
        args.Request.Data.Properties.Description = "test";
        args.Request.Data.Properties.Title = "test";
        args.Request.Data.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));
        deferral.Complete();

    }

以上代码显示 'Preparing content to share' 视图,但未显示共享图像的应用程序列表。

但是,如果我使用 DataPackage.SetText.

,一切正常

想不通 problem.Please 帮帮我!

以下两个链接帮助我捕获了屏幕截图。

Taking Screenshot

Saving and Sharing Screenshot

将图像保存到文件,然后附加文件,像这样进行 DataPackage:

    args.Request.Data.SetStorageItems(new List<IStorageFile> { yourPngFile });