Created
September 17, 2018 12:06
-
-
Save TheAlphamerc/0a537cb8fc14aab405307e98e175566b to your computer and use it in GitHub Desktop.
Capture Screenshot xamarin android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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