Android Semitransparent Bitmap Background Is Black
I'm trying to create semitransparent bitmaps, I used this code: private Bitmap SemiTransparent(Bitmap bitmap, int opacity) { // Create an array to hold the data of bitmap for
Solution 1:
Use this method to make a bitmap transparent:
/**
* @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)
{
BitmapmutableBitmap= bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvascanvas=newCanvas(mutableBitmap);
intcolour= (opacity & 0xFF) << 24;
canvas.drawColor(colour, PorterDuff.Mode.DST_IN);
return mutableBitmap;
}
See an explanation here: http://blog.uncommons.org/2011/01/12/adjusting-the-opacity-of-an-android-bitmap/
In the blog-post it checks if the bitmap is mutable or not - which can cause problems if the bitmap is mutable but doesn't have the config ARGB_8888 - so use my method instead.
Post a Comment for "Android Semitransparent Bitmap Background Is Black"