Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

[UWP]How to use async and await methods in Xamarin.UWP


I want to get the stream of the object. I tried the below code, but is not working. When I call the async method, it returns the value. memoryStream value always null.


public async Task<Stream> GetStream_UWP()
    Stream memoryStream ;
    var renderTargetBitmap = new RenderTargetBitmap();
    await renderTargetBitmap.RenderAsync(button);
    var pixels = await renderTargetBitmap.GetPixelsAsync();
    Guid encoderId = BitmapEncoder.JpegEncoderId;
    using (memoryStream = new MemoryStream())
        var encoder = await BitmapEncoder.CreateAsync(encoderId, memoryStream.AsRandomAccessStream());
        encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)renderTargetBitmap.PixelWidth,
            (uint)renderTargetBitmap.PixelHeight, 96.0, 96.0, pixels.ToArray());

        await encoder.FlushAsync();

    return memoryStream;

Please suggest me.


  • kentuckerkentucker USMember ✭✭✭✭✭

    I dont see where you actually get any pixel data to set.

Sign In or Register to comment.