如何将相对布局保存为位图图像....?在运行时我将图像添加到相对布局..然后如何将其保存为位图图像.
我对这个概念一无所知......请为此提出解决方案.
谢谢.
创建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"/>
Run Code Online (Sandbox Code Playgroud)
然后在您的活动中使用此代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4376 次 |
| 最近记录: |