2012-04-01 40 views
2

我正在創建一個基本上將drawable放入imageView onClick的應用程序。結果是在某些地方有一組圖像的屏幕。我想將此屏幕保存爲用戶手機上SD卡上的圖像。我已經知道如何將一個imageView轉換爲位圖並將其保存到SD卡,但是如何將所有的imageViews作爲一個文件保存在屏幕上?Android:將xml佈局(imageviews等)的所有內容保存爲圖像文件

我已經搜索了幾天的答案。我首先想到的是在一個可以截取屏幕截圖的按鈕中進行編程,但是我正在閱讀的所有內容都表示,您只能在根植手機上使用屏幕截圖。

任何幫助將不勝感激。謝謝!

+0

http://stackoverflow.com/questions/3107527/android-save-view-to-jpg-or-png – thaussma 2012-04-01 01:15:14

+0

你可以在這裏找到解決方案:http://stackoverflow.com/questions/5939987/android-take-screenshot-via-code。另外,請閱讀所選答案的評論。 – Arci 2012-04-01 01:24:45

+0

非常感謝你的工作! – SillyFidget 2012-04-01 15:24:18

回答

1
Bitmap bitmap = findViewById(your_layout_id).getDrawingCache(); 
File file = new File(path_to_store_file); 
if(!file.exists())  
    file.createNewFile(); 
try{ 
    FileOutputStream ostream = new FileOutputStream(file); 
    bitmap.compress(CompressFormat.PNG, 100, (OutputStream)ostream); 
} 
catch (Exception e) 
{ 
    e.printStackTrace(); 
}