我的Android代码在视频通话时截屏时遇到问题
我找到了几种在特定布局上截取屏幕截图的方法,这就是我使用的方法:
private void takeScreenshot() {
final FrameLayout container = (FrameLayout) findViewById(R.id.remote_video_view_container);
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
// create bitmap screen capture
container.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(container.getDrawingCache());
container.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
if(mPath!=null){
Toast savedToast = Toast.makeText(getApplicationContext(),
"Drawing saved to Gallery!", Toast.LENGTH_SHORT);
savedToast.show();
}
else{
Toast unsavedToast = Toast.makeText(getApplicationContext(),
"Oops! Image could not be saved.", Toast.LENGTH_SHORT);
unsavedToast.show();
}
outputStream.flush();
outputStream.close();
openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or DOM
e.printStackTrace();
}
}
private void openScreenshot(File imageFile) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(imageFile);
intent.setDataAndType(uri, "image/*");
startActivity(intent);
}
我尝试使用此代码保存我的绘图绘制应用程序,它将保存绘图布局,然后我尝试使用相同的方法来保存视频通话布局但返回黑屏图像。 我发现当我想在视频中记录它时,这种方法不能实时使用
来源:How to programmatically take a screenshot in Android?
所以,有人帮我解决问题的最佳方法是什么?