Android Imageview图形捕捉器未按需要提供

Android Imageview图形捕捉器未按需要提供,android,bitmap,imageview,android-framelayout,drawingcache,Android,Bitmap,Imageview,Android Framelayout,Drawingcache,我在框架布局中有图像视图,我在运行时将随机标签放在图像视图上,但当我使用框架布局绘图捕捉保存图像位图时,图像保存,但不必要的黑色部分出现在保存的图像中 我想要没有这个黑色部分的位图。请帮助。这是我的布局和代码 <FrameLayout android:id="@+id/fl_effect_view" android:layout_width="match_parent" android:layout_height="wrap_content" andro

我在框架布局中有图像视图,我在运行时将随机标签放在图像视图上,但当我使用框架布局绘图捕捉保存图像位图时,图像保存,但不必要的黑色部分出现在保存的图像中

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

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

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

ImageView bottomImage = (ImageView) findViewById(R.id.im_gselected_image);
f1.layout(0, 0, bottomImage.getMeasuredWidth(), bottomImage.getMeasuredHeight());
Bitmap b=Bitmap.createBitmap(f1.getDrawingCache(true));
这将强制您的结果具有特定的大小和位置,并将裁剪超出定义边界的所有内容

如果这对你有用,请告诉我

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