<分区>
如何将相对布局保存为位图图像....? 在运行时我将图像添加到相对布局..然后如何将它保存为位图图像。
我对这个概念一无所知...请提出解决方案。
谢谢。
标签 android
<分区>
如何将相对布局保存为位图图像....? 在运行时我将图像添加到相对布局..然后如何将它保存为位图图像。
我对这个概念一无所知...请提出解决方案。
谢谢。
最佳答案
创建一个 XML 文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
然后在您的 Activity 中使用此代码:
View content = findViewById(R.id.rlid);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/sdcard/" + yourimagename + ".png");
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 10, ostream);
ostream.close();
content.invalidate();
} catch (Exception e) {
e.printStackTrace();
} finally {
content.setDrawingCacheEnabled(false);
}
关于android - 如何将图像保存为 RelativeLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12986019/