我想轉換我的應用程序的屏幕並將其轉換爲位圖。我已經知道如何將視圖轉換爲位圖,但這不是我想要的,因爲我的屏幕由許多碎片組成。因此,我希望能夠把屏幕,並將其轉換成位圖... 幫助高度讚賞謝謝。Android將當前屏幕轉換爲位圖
5
A
回答
9
你可以使用這樣的事情並通過佈局一個視圖;)
public Bitmap takeScreenShot(View view) {
// configuramos para que la view almacene la cache en una imagen
view.setDrawingCacheEnabled(true);
view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
view.buildDrawingCache();
if(view.getDrawingCache() == null) return null; // Verificamos antes de que no sea null
// utilizamos esa cache, para crear el bitmap que tendra la imagen de la view actual
Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
view.destroyDrawingCache();
return snapshot;
}
0
View是你的根佈局: -
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString(R.string.free_tiket)+".jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b, "Screen", "screen");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
見鏈接的詳細信息: -
http://code.google.com/p/android-screenshot-library/wiki/DeveloperGuide
+0
也許你沒有看到我的上述評論。我不想實際拍攝截圖。只需將屏幕轉換爲位圖並將其設置爲ImageView的ImageBitmap即可。 – SynerFlow
0
View rootView = findViewById(R.id.relative_facebook).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
相關問題
- 1. 將鼠標轉換爲屏幕位置
- 2. 將Iphone屏幕轉換爲Ipad屏幕
- 3. 將silverlight3當前屏幕轉換爲字節數組的方法
- 4. 如何將屏幕座標轉換爲android中的位置點
- 5. android將位圖轉換爲ascii位圖
- 6. 以當前屏幕的屏幕截圖
- 7. 當前android的屏幕截圖活動
- 8. 如何將屏幕位置轉換爲等距位置
- 9. XNA 2D將世界位置轉換爲屏幕位置
- 10. 以當前屏幕截圖
- 11. Android - 圖像轉換增益屏幕
- 12. 將圖像轉換爲位圖android
- 13. 將屏幕分接位置轉換爲屏幕中心的極點
- 14. Android:將imageview轉換爲位圖,灰度,將位圖轉換爲imageview
- 15. 列表視圖的屏幕截圖並將其轉換爲位圖
- 16. 將視圖的觸摸位置轉換爲WebView的HTML屏幕位置
- 17. Android屏幕定位意圖
- 18. 將屏幕轉換爲primefaces數據表
- 19. 將屏幕轉換爲SP 4326
- 20. 將位圖轉換爲byteArray android
- 21. Android:將字符串轉換爲位圖
- 22. 將byteArray轉換爲android中的位圖?
- 23. 在Android中將位圖轉換爲GrayScale
- 24. android將位圖轉換爲bufferedinputstream
- 25. Android gif - 將位圖轉換爲電影
- 26. Android Studio - 將位圖轉換爲java.io.File
- 27. Android將Ninepatch資源轉換爲位圖
- 28. Android:將位圖轉換爲輸入流
- 29. 在android中將位圖轉換爲jpeg
- 30. 在屏幕地圖上將平面圖位置轉換爲座標
那麼截圖? https://code.google.com/p/android-screenshot-library/ – shkschneider
你看,我不希望用戶知道截圖已被採取。只是捕獲屏幕加載到位圖,然後將位圖設置爲圖像視圖 – SynerFlow