android - 如何将图像保存为 RelativeLayout

标签 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/

相关文章:

Android:在 ListView 周围绘制自定义边框?

android - 更改 recyclerview 中所有其他元素的背景

android - 在android中扩展相机 View ?

android - 无法使用图形 View 库

android - 我如何在Android的Text To Speech类中找到印度口音

java - 单击时表格行的背景颜色

java - android 过滤json文件并保存到arraylist

java - 我有一个关于显示器问题的非常菜鸟的询问

android - 如何在 Android 中使用常见的 UI 样式?

Android工具栏显示标题结束