透明位图为黑色



我有两个重叠的图像视图。我希望其中一个保持不变,而另一个完全透明。我正在用画布绘制透明位图,但我无法获得透明位图。我该如何纠正?

当我使用bitmap.eraseColor(color)将其颜色设置为更接近透明颜色(通过减少alpha通道)时,它会变得越来越接近黑色。当我将其设置为bm.eraseColor(Color.Transparent)时,它显示为完全黑色。包含位图的imageview有一个透明的背景,所以我可以从黑色位图(应该是透明的)的外部显示它。

bm.add(decodeSampledBitmapFromResource(
    getIntent().getExtras().getString("filePath"),
    iv.getHeight(), iv.getWidth()).copy(
        Bitmap.Config.ARGB_8888, true));
    scaleBitmap();
    originalImage.setImageBitmap(bm.get(N).copy(
        Bitmap.Config.ARGB_8888, false));
    bm.get(N).eraseColor(Color.TRANSPARENT);
    iv.setImageBitmap(bm.get(N));

以下是布局代码的相关部分:

<RelativeLayout
    android:id="@+id/myImages"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="6"
     >
    <ImageView
        android:id="@+id/originalImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:scaleType="centerInside"
        android:visibility="visible" />
    <com.abacus.colorsketch.MyImageView
        android:id="@+id/workingImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/transparent"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:scaleType="centerInside" />
</RelativeLayout>

您需要在eraseColor之前调用setHasAlpha

最新更新