2
我想从我的android应用拍摄一张照片,但由于我当前的Activity中有videoView,所以我得到一张黑色图像。我怎么能没有root权限?我怎样才能调用android截图系统?
波纹管代码即可获得我目前的观点:
在我的主要活动:
saveBitmap(tackeScreenshot());
和方法使用:
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
File imagePath = new File("/sdcard/image.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Functions.Log("saveBitmap", e.getMessage());
} catch (IOException e) {
Functions.Log("saveBitmap", e.getMessage());
}
}
参见[这个](http://stackoverflow.com/a/27454425/3531756)。 – 2015-03-02 12:35:27
在'takeScreenshot()'中,你不会返回正确的类型。你应该返回一个**位图**。但是,您返回**视图**,而是。这不是'saveBitmap()'所期望的。 – 2015-03-02 12:48:32