0
A
回答
4
试试这个:
private void takeScreenshot() {
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
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
openScreenshot(imageFile);
} catch (Throwable e) {
// Several error may come out with file handling or OOM
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);
}
添加此权限保存文件:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
相关问题
- 1. 如何获取NSStatusItem的屏幕位置
- 2. 在Android上获取主屏幕位置
- 3. 如何从videofile获取屏幕截图?
- 4. 如何获取XYSeries x位置的屏幕x位置?
- 5. iOS:获取屏幕截图
- 6. ffmpeg获取屏幕截图
- 7. 如何使用adbkit获取Android屏幕截图
- 8. 获取屏幕位置的底部
- 9. 获取相对的屏幕位置
- 10. 将GLSurfaceView的屏幕捕获到位图
- 11. 屏幕捕获的代码屏幕捕获Android的任何屏幕
- 12. android获取其他屏幕方向的屏幕大小
- 13. 获取Android中的主屏幕数量?
- 14. Android - 拟合位图到屏幕
- 15. Android:可滚动(位图)屏幕
- 16. 在屏幕上获取按钮位置
- 17. 如何截取这里地图加载的android屏幕截图?
- 18. 如何为完整的Android屏幕分辨率提供位图?
- 19. 如何获取活动工作簿的屏幕位置?
- 20. 如何获取Swing元素的屏幕位置?
- 21. 如何获取TWinControl的X,Y位置(相对于屏幕)
- 22. 如何在UIWebview中获取屏幕上的视频位置
- 23. 如何获取OSX中DockTile的屏幕位置?
- 24. 如何获取CSS3-3d转换元素的屏幕位置?
- 25. OSX/Cocoa:获取屏幕上的Dockless图标的绝对位置
- 26. 捕获android屏幕
- 27. 将屏幕捕获到位图
- 28. 如何滚动屏幕内存位图
- 29. ASP.NET - 获取屏幕特定区域的屏幕截图?
- 30. Android屏幕取向
退房:HTTP:// stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-in-android –
我想获取位图而不需要屏幕截图。请帮助我如何做到这一点。 – Gazal
'我想获取位图而不需要屏幕截图。“你知道**这是废话吗? –