因此,我正在尝试创建一个函数,该函数实际上将截取当前应用程序活动的屏幕截图并在共享之前将其显示在屏幕上,但是当它到达我用来显示屏幕截图的屏幕时,它会耗尽内存到分享的地步。
// image naming and path to include sd card appending name you choose for file
Java.IO.File dir = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures), "ScreenShots");
if (!dir.Exists())
dir.Mkdirs();
// create bitmap screen capture
Bitmap bitmap;
View v1 = act.RootView;
v1.DrawingCacheEnabled = true;
bitmap = Bitmap.CreateBitmap(v1.DrawingCache);
v1.DrawingCacheEnabled = false;
string date = DateTime.Now.ToString();
date = date.Replace('/', '-');
Java.IO.File _file = new Java.IO.File(dir, from + date + ".png");
try
{
using (var stream = System.IO.File.Create(_file.AbsolutePath))
{
bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, stream);
stream.Flush();
stream.Close();
}
bitmap.Dispose();
v1.Dispose();
}
catch (Java.IO.FileNotFoundException e)
{
// TODO Auto-generated catch block
e.PrintStackTrace();
}
catch (Java.IO.IOException e)
{
// TODO Auto-generated catch block
e.PrintStackTrace();
}
我试图找到一种在不牺牲太多质量的情况下做到这一点的好方法。任何帮助不胜感激=]
更新:我尝试这样做与上述相反,也没有运气。
View v1 = act.RootView;
v1.DrawingCacheQuality = DrawingCacheQuality.Low;
v1.DrawingCacheEnabled = true;
Bitmap bitmap = Bitmap.CreateScaledBitmap(v1.GetDrawingCache(true),720,1280,false);
v1.DrawingCacheEnabled = false;
v1.DestroyDrawingCache();
v1.Dispose();