想我有一个从媒体商店的专辑封面加载的位图,它有 100% 的透明值,我怎样才能将其更改为 50 或 30?
另外,您知道我可以使图像变成黑白的任何方法吗?
谢谢
使用以下方法:
/**
* @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/
将 alpha 设置在 0 到 255 之间!!
alpha 设置为 45 将使图像透明
ViewName.getBackground().setAlpha(65);