2012-04-01 36 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(); 
}