:
The first type:
The second type:
The first is a canvas-drawn effect:
public void First (View v) {//Prevent immutable bitmap passed to Canvas constructor error bitmap Bitmap1 = BITMAPFA Ctory.decoderesource (Getresources (), r.drawable.apple). Copy (Bitmap.Config.ARGB_8888, true); Bitmap bitmap2 = ((bitmapdrawable) getresources (). getdrawable (R.drawable.go)). Getbitmap (); Bitmap newbitmap = null; Newbitmap = Bitmap.createbitmap (BITMAP1); Canvas canvas = new canvas (NEWBITMAP); Paint paint = new paint (); int w = bitmap1.getwidth (); int h = bitmap1.getheight (); int w_2 = Bitmap2.getwidth (); int h_2 = Bitmap2.getheight (); Paint.setcolor (Color.gray); Paint.setalpha (125); Canvas.drawrect (0, 0, bitmap1.getwidth (), Bitmap1.getheight (), paint); Paint = new paint (); Canvas.drawbitmap (BITMAP2, Math.Abs (w-w_2)/2, Math.Abs (h-h_2)/2, paint); Canvas.save (Canvas.all_save_flag); Storing pictures of new compositions canvas.resTore (); Image.setimagebitmap (NEWBITMAP); }
Canvas canvas = new canvas (NEWBITMAP); When you create a canvas with Newbitmap, the operation is already implemented on the diagram.
This example can be done to start playing the effect of the player, calculate the middle position, first cover a layer of transparent gray square, and then in the middle of the picture of the button to play.
The second is to use the system's Layerdrawable class, which is primarily used to control the combination of multiple images:
public void second (View v) { Bitmap Bitmap1 = ((bitmapdrawable) getresources (). getdrawable ( r.drawable.apple)) . Getbitmap (); Bitmap bitmap2 = ((bitmapdrawable) getresources (). getdrawable ( r.drawable.go)). Getbitmap (); drawable[] array = new DRAWABLE[2]; Array[0] = new bitmapdrawable (BITMAP1); ARRAY[1] = new bitmapdrawable (BITMAP2); Layerdrawable la = new layerdrawable (array); The first parameter is the index number of the layer, and the following four parameters are left, top, right, and bottom la.setlayerinset (0, 0, 0, 0, 0); La.setlayerinset (1, A, A, a); Image.setimagedrawable (LA); }
Associative arrays array, controlling the position of each layer
Note: The above prevents immutable bitmap passed to Canvas constructor errors
The reason is that if you do not use the Copy method, the direct reference will modify the resource file, and Android is not allowed in the code to modify the image in the res file
Android Picture Overlay effect--two ways