Converting FrameLayout as Bitmap

隐身守侯 提交于 2020-01-10 20:00:09

问题


I have a FrameLayout that consist some Image views & one EditText. I am saving this layout as an image in the memory (external). First time when I set the images in imageviews everything goes fine i.e. the exact image is being saved (same as displaying on screen) but when after saving first time if I change any thing (text, image) it displays correctly on screen but in saved image it displays earlier image (first image).

XML of Layout:

<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>

Code that change it in bitmap is:

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

I used this bm for saving.

Thanks for helping.


回答1:


to overcome with this problem I destroy the drawingcache after saving the image.

savedImage.destroyDrawingCache();


来源:https://stackoverflow.com/questions/10534247/converting-framelayout-as-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!