我正在尝试拍摄屏幕截图并将其保存为sdcard上的png文件。我的文件以1.57Kb的文件大小保存,但是它是黑色的。我使用下面的代码:屏幕截图为黑色
View content = findViewById(R.id.id_ll_SurfaceView);
content.setDrawingCacheEnabled(true);
Bitmap b = content.getDrawingCache();
b.createBitmap(800, 480, Config.ARGB_8888);
File file = new File("/sdcard/test.png");
try
{
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
FileOutputStream(
Environment.getExternalStorageDirectory().getAbsoluteFile()+"/test.jpg"));
b.compress(CompressFormat.PNG, 100, fos);
fos.close();
Toast.makeText(getApplicationContext(), "Saved", 0).show();
}
catch (Exception e)
{
e.printStackTrace();
}
你在哪里调用代码?视图'id_ll_SurfaceView'已经在执行此代码的屏幕上呈现? – Karthik
你也可以查看[这里](http://stackoverflow.com/questions/8294110/taking-screenshot/8366223#8366223)。 –
'b.createBitmap(800,480,Config.ARGB_8888);'行是完全无用的......''createBitmap'是静态函数,你忽略了返回的位图。我认为你的意思是调整位图的大小。 – st0le