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
'我想獲取位圖而不需要屏幕截圖。「你知道**這是廢話嗎? –