我想从我的Android应用程序中拍照,但由于我在当前活动中的videoView,我得到了一张黑色图片。如何在没有root权限的情况下接受它?
bellow是获取我当前视图的代码:
在我的主要活动中:
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());
}
}
答案 0 :(得分:0)
你应该做这样的事情
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;
// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
然后,当你需要访问时使用这样的东西:
Uri uri = Uri.fromFile(new File(mPath));