-1

我在框架布局中有图像视图,我在运行时在图像视图上放置了随机标签,但是当我使用框架布局绘图保存图像位图时,然后图像保存,但在保存的图像中出现了不必要的黑色部分。实际图像

用贴纸保存后

必需的

我想要没有这个黑色部分的位图。请帮忙。这是我的布局和代码。

<FrameLayout
    android:id="@+id/fl_effect_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/rl_title"
    android:layout_marginBottom="83dp" >

    <ImageView
        android:id="@+id/im_gselected_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
         >
    </ImageView>
</FrameLayout>

这是我用来创建位图的代码。

FrameLayout fl=(FrameLayout) findViewById(R.id.fl_effect_view);
f1.setDrawingCacheEnabled(true);
Bitmap b=Bitmap.createBitmap(f1.getDrawingCache());
f1.setDrawingCacheEnabled(false);
4

1 回答 1

2

在获取绘图缓存之前尝试设置视图的大小:

ImageView bottomImage = (ImageView) findViewById(R.id.im_gselected_image);
f1.layout(0, 0, bottomImage.getMeasuredWidth(), bottomImage.getMeasuredHeight());
Bitmap b=Bitmap.createBitmap(f1.getDrawingCache(true));

这将强制您的结果具有特定的大小和位置,并将裁剪超出您定义范围的所有内容。

如果这对你有用,请让我现在。

于 2014-02-06T20:50:09.217 回答