Mã hoạt động tốt cho ảnh chụp màn hình đầu tiên và tiếp tục chụp cùng một ảnh chụp màn hình bất kể chuyển sang chế độ xem khác.Android - Không chụp màn hình của màn hình hiện tại
Cách tải ảnh chụp màn hình hiện tại?
public void saveBitmap(Bitmap bitmap) {
File imagePath = new File(Environment.getExternalStorageDirectory() + "/" + new SimpleDateFormat("yyyyMMddhhmmss'.jpg'").format(new Date()));
FileOutputStream fos =null;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
thông tin nhấp chuột:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iSave:
Bitmap bitmap = null;
bitmap = takeScreenshot();
saveBitmap(bitmap);
break;
}
}
đây:
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
bài takeScreenshot() phương pháp. –
posted .. @rajatmehra – Fou
Thử getWindow(). GetDecorView(). GetRootView() thay vì findViewById (android.R.id.content) .getRootView(). –