Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataPackage.SetBitmap在Windows phone 8.1 WinRT应用程序中不工作_C#_Asp.net_Windows Phone 8.1_Winrt Xaml - Fatal编程技术网

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

C# DataPackage.SetBitmap在Windows phone 8.1 WinRT应用程序中不工作,c#,asp.net,windows-phone-8.1,winrt-xaml,C#,Asp.net,Windows Phone 8.1,Winrt Xaml,我正在使用以下代码在我的windows phone 8.1应用程序中共享图像 private async void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { var deferral = args.Request.GetDeferral(); var bitmap = new RenderTargetBitmap();

我正在使用以下代码在我的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();

    }
上面的代码显示了“准备共享内容”视图,但没有显示共享图像的应用程序列表

但是,如果我使用DataPackage.SetText,一切正常


我想不出这个问题,请帮帮我

下面的两个链接帮助我捕获了截图


将图像保存到文件,然后将文件附加到数据包,如下所示:

    args.Request.Data.SetStorageItems(new List<IStorageFile> { yourPngFile });
args.Request.Data.setStorage项目(新列表{yourPngFile});