1. Mohammad Ghazanfar Khan's Avatar
    I want to share an image in my windows phone 8.1 application using DataTransferManager.
    For this I use my windows 8.1 app code for sharing using DataTransfer which works fine on Windows 8.1 but it doesnt work on WP8.1.

    Here is my approach, I am converting my canvas into an image using RenderBitmap class then creating a RandomAccessStream of the bitmap to use in SetBitmap method.

    args.Request.Data.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    base.OnNavigatedTo(e);
    DataTransferManager.GetForCurrentView().DataRequested+= MainPage_DataRequested;
    }

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

    // 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.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));
    args.Request.Data.Properties.Description = "description";
    args.Request.Data.Properties.Title = "title";
    deferral.Complete();
    }

    This does not give any error but the image is not seen in the sharing apps like Messaging,OneNote etc.This code works fine in windows 8.1 app.Please need help stuck here for a long time.
    07-21-2014 04:17 PM
  2. Laura Knotek's Avatar
    Hi and welcome to WPCentral.

    I've moved your thread to the Developers Corner forum, since other developers will be able to assist you with coding better than regular users.
    07-21-2014 11:49 PM
  3. Expression2's Avatar
    MSDN says this class (DataTransferManager) works only in native apps. Check the documentation.
    07-24-2014 02:47 AM
  4. Vitor Salvatore Pierce's Avatar
    MSDN says this class (DataTransferManager) works only in native apps. Check the documentation.
    "Windows Phone 8
    This API is supported in native apps only."
    Said 8.0 and not 8.1.
    07-26-2014 05:05 AM

Similar Threads

  1. How do you use your 930?
    By AirSlab in forum Nokia Lumia 930
    Replies: 8
    Last Post: 07-22-2014, 06:33 PM
  2. Is possible to unlock my phone from my carrier?
    By WP_290 in forum Ask a Question
    Replies: 4
    Last Post: 07-22-2014, 12:28 PM
  3. What to use $20 Credit on?
    By mmbond in forum Nokia Lumia 1520
    Replies: 8
    Last Post: 07-21-2014, 08:01 PM
  4. I need a similar app to AirSync
    By ULOP3Z in forum Windows Phone 8
    Replies: 0
    Last Post: 07-21-2014, 03:46 PM
  5. Modern Combat 5 hitting Windows and Windows Phone this Thursday
    By WindowsCentral.com in forum Windows Central News Discussion
    Replies: 0
    Last Post: 07-21-2014, 03:11 PM
LINK TO POST COPIED TO CLIPBOARD