locked
Share image with facebook

    Question

  • Can somebody help me with this one please?

    I'm trying to share an image already saved in the app local folder with facebook using the share charm. Everything works fine with the other apps showing on the share charm like Onenote and Mail, I mean I can see the image but not with facebook. I don't want to use any other way, but the share charm. I've seen in other apps like photoshop express that this can be done. Here is my code for rendering the image and showing the share charm. Thanks in advance.

    private async void ShareTextHandler(DataTransferManager sender, DataRequestedEventArgs e)
            {
                DataRequestDeferral deferal = e.Request.GetDeferral();
    
                Task task;
                task = RenderImageSource();
                await Task.Delay(250);
                var folder = ApplicationData.Current.LocalFolder;
                var file = await folder.GetFileAsync("weather.png");
                var randomAccessStreamReference = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file);
    
                DataRequest request = e.Request;
                
                request.Data.Properties.Title = "Got the Weather";
                request.Data.Properties.Description = "Share your weather";
                request.Data.SetBitmap(randomAccessStreamReference);
                
                deferal.Complete();
            }
    
            private async Task RenderImageSource()
            {
                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                await renderTargetBitmap.RenderAsync(CurrentGrid, 0, 0);
    
                var folder = ApplicationData.Current.LocalFolder;
                var file = await folder.CreateFileAsync("weather.png", CreationCollisionOption.ReplaceExisting);
                var pixelBuffer = await renderTargetBitmap.GetPixelsAsync();
                var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
    
                using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
                    encoder.SetPixelData(
                        BitmapPixelFormat.Bgra8,
                        BitmapAlphaMode.Ignore,
                        (uint)renderTargetBitmap.PixelWidth,
                        (uint)renderTargetBitmap.PixelHeight,
                        logicalDpi,
                        logicalDpi,
                        pixelBuffer.ToArray());
    
                    await encoder.FlushAsync();
                }
            }

     

    Thursday, March 05, 2015 7:50 PM

Answers

  • Try sharing from the Share Source sample to see if it can share the data you want to Facebook and Twitter. If not then the problem is that those Share Targets don't do what you need.

    In that case you would need to go directly to the Facebook and Twitter APIs. You can find information on those from https://developers.facebook.com/ and http://dev.twitter.com


    Best Regards,
    Please remember to mark the replies as answers if they help

    • Marked as answer by giannisdolon Friday, March 06, 2015 7:36 PM
    Friday, March 06, 2015 9:22 AM

All replies

  • Try sharing from the Share Source sample to see if it can share the data you want to Facebook and Twitter. If not then the problem is that those Share Targets don't do what you need.

    In that case you would need to go directly to the Facebook and Twitter APIs. You can find information on those from https://developers.facebook.com/ and http://dev.twitter.com


    Best Regards,
    Please remember to mark the replies as answers if they help

    • Marked as answer by giannisdolon Friday, March 06, 2015 7:36 PM
    Friday, March 06, 2015 9:22 AM
  • Thank you very much. That's exactly what I was looking for. Apparently the storageItem property was the key. Thanks again.
    Friday, March 06, 2015 7:38 PM