In two ways, the first idea is to get the bitmap pixel value into a int[] array by manipulating the bitmap, because bitmap is usually the ARGB8888 format in Android, so the highest bit is the value of a channel, After the alignment is changed, create a new bitmap. The second idea is to change the transparency of the view by setting the transparency of the canvas's paint and then Canvas.drawbitmap (). The specific code is as follows:
The first way of thinking:
public static Bitmap Gettransparentbitmap (Bitmap sourceimg, int number) {int[] argb = new Int[sourceimg.getwidth () * source Img.getheight ()];sourceimg.getpixels (ARGB, 0, Sourceimg.getwidth (), 0, 0, sourceimg.getwidth (), Sourceimg.getheight ( );//Get the ARGB value of the picture number = # 255/100;for (int i = 0; i < argb.length; i++) {Argb[i] = (# << 24) | (Argb[i] & 0X00FFFFFF);} sourceimg = Bitmap.createbitmap (ARGB, Sourceimg.getwidth (), Sourceimg.getheight (), config.argb_8888); return sourceimg;}
The above code by my pro-test available, fixed the link two errors. The range of number is 0-100,0, which means that it is completely transparent and completely invisible. One of the most critical steps you can see is argb[i] = (number << 24) | (Argb[i] & 0X00FFFFFF); Pass(Argb[i] & 0X00FFFFFF) Set the A-channel of the pixel at point I to 0, and then (num<<24) to do or operate. Shift See links
The second way of thinking:
Example code:
Class Drawcanvas extends View {public Drawcanvas (context context) { super (context); } @Override protected void OnDraw (canvas canvas) { super.ondraw (canvas); Get resource picture of Bitmap Bitmap vbitmap = Bitmapfactory.decoderesource (This.getresources () , R.drawable.icon ); Build Paint Object paint vpaint = new paint (); Vpaint. SetStyle (Paint.Style.STROKE); Hollow Vpaint. Setalpha (); Canvas.drawbitmap (Vbitmap, +, +, null); Non-transparent canvas.drawbitmap (Vbitmap, vpaint); Transparent } }
About Canvas.drawbitmap See links
Both methods have their uses and which ones are used.