【发布时间】:2016-02-07 17:38:21
【问题描述】:
在搜索“如何将布局视图保存为图像”之后,我找到了一些保存在内部和外部存储中的解决方案。但似乎创建的图像文件将保存在一些通常不可见的 data/data/... 文件夹中。实际上,我希望用户可以在图库中看到图像。我找到了一些类似下面的代码,但我什至无法检查图像是否已创建:
View content = findViewById(R.id.relativeLayout);
String yourimagename = "MyImageFile";
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/" + yourimagename + ".png");
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 10, ostream);
ostream.close();
content.invalidate();
} catch (Exception e) {
e.printStackTrace();
} finally {
content.setDrawingCacheEnabled(false);
}
【问题讨论】:
标签: android image file image-processing save