将FrameLayout转换为位图

4

我有一个FrameLayout,其中包含一些ImageView和一个EditText。我将此布局保存为内存中的图像(外部)。第一次设置图像视图中的图像时,一切都很好,即保存了精确的图像(与屏幕上显示的相同),但是当我在第一次保存后更改任何内容(文本、图像)时,它在屏幕上正确显示,但在保存的图像中显示先前的图像(第一张图片)。

布局的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<FrameLayout 
    android:id="@+id/imageWithoutFrame"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_centerInParent="true" >

    <ImageView
        android:id="@+id/withoutFrame_background"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/background" />

    <ImageView
        android:id="@+id/withoutFrame_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:layout_gravity="center" />

    <EditText 
        android:id="@+id/withoutFrame_editableText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"
        android:layout_marginBottom="30dip"
        android:hint="Write here"
        android:maxLength="60" />

</FrameLayout>
</RelativeLayout>

将其转换为位图的代码如下:

Bitmap bm = null;
FrameLayout savedImage = null;
savedImage = (FrameLayout)findViewById(R.id.imageWithoutFrame);
savedImage.setDrawingCacheEnabled(true);
savedImage.buildDrawingCache();
bm = savedImage.getDrawingCache();

我使用这个书签来保存。
感谢你的帮助。
1个回答

3
为了解决这个问题,我在保存图像后销毁了绘图缓存。
savedImage.destroyDrawingCache();

你的解决方案和 view.setDrawingCacheEnabled(false) 有什么不同? - Dr.jacky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接