【问题标题】:Imageview Drawing catch not come as neededImageview 绘图捕获未按需提供
【发布时间】:2013-12-13 10:42:13
【问题描述】:

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

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

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

【问题讨论】:

    标签: android bitmap imageview android-framelayout drawingcache


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2014-03-13
      • 1970-01-01
      • 2017-01-04
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多