Making screen capture in xamarin.forms

前端 未结 2 1751
盖世英雄少女心
盖世英雄少女心 2020-12-05 21:52

Is there a package that does screen capture in xamarin.forms ?

I need also to capture google maps screen shots

2条回答
  •  时光取名叫无心
    2020-12-05 22:36

    Implementation for UWP

    public async Task CaptureAsync()
    {
        //create and capture Window
        var renderTargetBitmap = new RenderTargetBitmap();
        await renderTargetBitmap.RenderAsync(Window.Current.Content);
    
        var pixelpuffer = await renderTargetBitmap.GetPixelsAsync();
        var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
    
        IRandomAccessStream stream = new InMemoryRandomAccessStream();
        BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
        encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Fant;
        encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight, logicalDpi, logicalDpi, pixelpuffer.ToArray());
        await encoder.FlushAsync();
        byte[] resultingBuffer = new byte[stream.Size];
    
        await stream.ReadAsync(resultingBuffer.AsBuffer(), (uint)resultingBuffer.Length, InputStreamOptions.None);
    
        return resultingBuffer;
    
    }
    

提交回复
热议问题