我正在尝试保存我的应用程序的屏幕截图。我的主屏幕是 SurfaceView,我正在创建一个新画布并将 SurfaceView 绘制到画布中。我有一个问题,因为我得到的 PNG 是完全透明的。
这是我的代码
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(image);
draw(c);
String path=Environment.getExternalStorageDirectory() + "/test2.png";
File file = new File(path);
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
image.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
Uri screenshotUri = Uri.parse("file://"+file.getAbsolutePath());
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setDataAndType(screenshotUri, "image/png");
startActivity(sendIntent);
}
catch (Exception e)
{
e.printStackTrace();
}