Using SetBitmap with the DataPackage does not work for some apps

ROger Oslon 1 Reputation point
2021-02-07T21:26:19.787+00:00

I am trying to implement the share app functionality using the DataRequest. I am creating a RenderTargetBitmap from a Grid shown on my app, saving it as a PNG file and then loading the file into my DataPackage with the SetBitmap method.

This is working but I am expecting apps like the Facebook and Instagram apps did not show in my list of apps to share, all I get is Mail and Onenote apps. Can anybody tell me if I am doing anything wrong or missing a step?

Here is my code that creates the request:

 var deferral = args.Request.GetDeferral();
             DataRequest request = args.Request;

             request.Data.Properties.Title = "Quote Collection";
             request.Data.Properties.Description = "Share your quote";

             RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();

             FlipViewItem item = (FlipViewItem)flipView.ContainerFromItem(flipView.SelectedItem);

             Grid grid = HelperMethods.FindElementByName(item, "QuoteGrid");
             await renderTargetBitmap.RenderAsync(grid);

             var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
             var pixels = pixelBuffer.ToArray();
             var displayInformation = DisplayInformation.GetForCurrentView();
             var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("quoteImage" + ".png", CreationCollisionOption.ReplaceExisting);
             using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
             {
                 var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
                 encoder.SetPixelData(BitmapPixelFormat.Bgra8,
                                      BitmapAlphaMode.Premultiplied,
                                      (uint)renderTargetBitmap.PixelWidth,
                                      (uint)renderTargetBitmap.PixelHeight,
                                      displayInformation.RawDpiX,
                                      displayInformation.RawDpiY,
                                      pixels);
                 await encoder.FlushAsync();
             }

             var qfile = await ApplicationData.Current.LocalFolder.GetFileAsync("quoteImage.png");

             request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(file));

             deferral.Complete();
0 comments No comments
{count} votes