xamarin / SignaturePad

MIT License
245 stars 150 forks source link

UWP Capture Screenshot not including Signature #104

Closed aherrick closed 7 years ago

aherrick commented 7 years ago

I have a Xamarin Forms page with the Signature Control. I'm attempting to capture a screenshot of the entire view. It should include the signature as well.

However, using the following code I'm noticing the signature does not show up.

What is the best way to capture the full Page including the signature? (not just the signature)

public class ScreenshotService : IScreenshotService
{
    public async Task<byte[]> CaptureAsync()
    {
        var rtb = new RenderTargetBitmap();
        await rtb.RenderAsync(Window.Current.Content);

        var pixelBuffer = await rtb.GetPixelsAsync();
        var pixels = pixelBuffer.ToArray();

        // Useful for rendering in the correct DPI
        var displayInformation = DisplayInformation.GetForCurrentView();

        var stream = new InMemoryRandomAccessStream();
        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
        encoder.SetPixelData(BitmapPixelFormat.Bgra8,
        BitmapAlphaMode.Premultiplied,
        (uint)rtb.PixelWidth,
        (uint)rtb.PixelHeight,
        displayInformation.RawDpiX,
        displayInformation.RawDpiY,
        pixels);

        await encoder.FlushAsync();
        stream.Seek(0);

        var readStram = stream.AsStreamForRead();
        var bytes = new byte[readStram.Length];
        readStram.Read(bytes, 0, bytes.Length);

        return bytes;
    }
}
mattleibow commented 7 years ago

Unfortunately this appears to be a limitation with the RenderTargetBitmap and the InkCanvas. This guy jumped through hoops: https://mtaulty.com/2016/02/16/windows-10-uwp-inkcanvas-and-rendertargetbitmap

You might be able to do something similar with the capture and then draw the signature over it - use GetImageStreamAsync.

aherrick commented 6 years ago

I came up with a decent solution here: https://stackoverflow.com/questions/47226577/xamarin-forms-uwp-capture-screenshot-include-signature-pad