我有两个重叠的 ImageView 。我希望一个保持不变,而另一个完全透明。我正在用 Canvas 绘制透明位图,但无法获得透明位图。我该如何纠正这个问题?
当我使用 bitmap.eraseColor(color)
将其颜色设置为更接近透明色(通过减少 alpha channel )时,它变得越来越接近黑色。当我将它设置为 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
。
关于android - 透明位图为黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17931451/