如何使图像透明android

时间:2012-05-16 03:59:06

标签: android

想想我有一个位图,我已经从Media Store中的Album Art加载了它,它具有100%的透明值,如何将其更改为50或30?

您也知道我可以将图像设为黑白图像吗?

感谢

2 个答案:

答案 0 :(得分:0)

将alpha设置为0到255 !!

alpha设置为45将使图像透明

ViewName.getBackground()setAlpha(65);

答案 1 :(得分:0)

使用以下方法:

/**
 * @param bitmap The source bitmap.
 * @param opacity a value between 0 (completely transparent) and 255 (completely
 * opaque).
 * @return The opacity-adjusted bitmap.  If the source bitmap is mutable it will be
 * adjusted and returned, otherwise a new bitmap is created.
 */
private Bitmap adjustOpacity(Bitmap bitmap, int opacity)
{
    Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
    Canvas canvas = new Canvas(mutableBitmap);
    int colour = (opacity & 0xFF) << 24;
    canvas.drawColor(colour, PorterDuff.Mode.DST_IN);
    return mutableBitmap;
}

这里的解释: http://blog.uncommons.org/2011/01/12/adjusting-the-opacity-of-an-android-bitmap/