Skip to content

Instantly share code, notes, and snippets.

@TheAlphamerc
Created September 17, 2018 12:06
Show Gist options
  • Save TheAlphamerc/0a537cb8fc14aab405307e98e175566b to your computer and use it in GitHub Desktop.
Save TheAlphamerc/0a537cb8fc14aab405307e98e175566b to your computer and use it in GitHub Desktop.
Capture Screenshot xamarin android
/// <summary>
/// Capture Screenshot xamarin android
/// </summary>
/// <returns> Byte[]</returns>
public async Task<byte[]> CaptureScreenAsync()
{
var activity = Forms.Context as Advantage.Swap.Droid.MainActivity;
if (activity == null)
{
return null;
}
var view = activity.Window.DecorView;
view.DrawingCacheEnabled = true;
Android.Graphics.Bitmap bitmap = view.GetDrawingCache(false);
byte[] bitmapData = null;
using (var stream = new MemoryStream())
{
bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 0, stream);
bitmapData = stream.ToArray();
}
return bitmapData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment