0
所以我試圖創建一個功能,將本質上採取當前應用程序活動的屏幕截圖,並在共享之前將其顯示在屏幕上,但當它到達屏幕時,它將耗盡內存在開始共享之前使用它來顯示屏幕截圖。Monodroid屏幕截圖內存
// 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();