Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android how to set opacity in bitmap xml
  2. <?xml version="1.0" encoding="utf-8"?>
  3. <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:src="@drawable/btn_home"
  5.     >
  6. </bitmap>
  7.        
  8. private Bitmap adjustOpacity(Bitmap bitmap, int opacity)
  9.     {
  10.         Bitmap mutableBitmap = bitmap.isMutable()
  11.                                ? bitmap
  12.                                : bitmap.copy(Bitmap.Config.ARGB_8888, true);
  13.         Canvas canvas = new Canvas(mutableBitmap);
  14.         int colour = (opacity & 0xFF) << 24;
  15.         canvas.drawColor(colour, PorterDuff.Mode.DST_IN);
  16.         return mutableBitmap;
  17.     }