2012-05-16 64 views
0

認爲我有一個位圖,我已經從媒體存儲中的相冊藝術中加載它,它具有100%透明值,我如何將它更改爲50或30?如何使圖像透明android

另外你知道任何方式,我可以使圖像黑色和白色?

謝謝

回答

0

設置α在0到255之間!

阿爾法設定爲45會使影像透明

ViewName.getBackground()setAlpha(65)。

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/