将 FrameLayout 转换为位图 [英] Converting FrameLayout as Bitmap

查看:38
本文介绍了将 FrameLayout 转换为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 FrameLayout,其中包含一些图像视图和一个编辑文本.我将此布局保存为内存(外部)中的图像.第一次在 imageviews 中设置图像时一切正常,即正在保存确切的图像(与在屏幕上显示相同)但是在第一次保存后,如果我更改任何内容(文本、图像),它会在屏幕上正确显示但已保存image 它显示较早的图像(第一张图像).

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:

<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();

我用这个 bm 来保存.

I used this bm for saving.

感谢您的帮助.

推荐答案

为了解决这个问题,我在保存图像后销毁了绘图缓存.

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

savedImage.destroyDrawingCache();

这篇关于将 FrameLayout 转换为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆