Android's image processing API is very helpful, but not suitable for writing games, writing games or using a dedicated engine is better.
Android image processing also has the processing of the API, feeling super-cock.
Let me first share the general processing of Android, such as panning, flipping, etc.:
Zoom, rotate, pan, mirror, reflection
Bitmap Bitmap1 =Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher); Img_one.setimagebitmap (BITMAP1); Bitmap Alterbitmap=Bitmap.createbitmap (Bitmap1.getwidth (), Bitmap1.getheight (), Bitmap1.getconfig ()); Canvas Canvas=NewCanvas (ALTERBITMAP); Paint Paint=NewPaint ();p aint.setcolor (Color.Black); Matrix Matrix=NewMatrix (); Matrix.setvalues (New float[]{ 0.5f, 0, 0, 0, 1, 0, 0, 0, 1});//Matrix.setscale (2.0f, 1);Canvas.drawbitmap (Bitmap1, Matrix, paint); Img_two.setimagebitmap (alterbitmap);
New Matrix (); // matrix.setrotate (180,bitmap1.getwidth ()/2,bitmap1.getheight ()/2); Matrix.setrotate (a); // Anti- aliasing paint.setantialias (true);
New Matrix (); // this is when the Drawbitmap () is changed. // Matrix.settranslate (ten); // the execution of this sentence occurs in translational matrix.posttranslate (10, 10);
New Matrix (); // This image to choose the right and left asymmetric effect is obvious Matrix.setscale ( -1,1 0);
New Matrix (); Matrix.setscale (1,-1); Matrix.posttranslate (0, Bitmap1.getheight ());
Synthesis
The main method is to draw two pictures on the canvas, Android provides the API to set the composition of these two images:
IV =(ImageView) Findviewbyid (R.ID.IV); Bitmap Bitmap=Bitmapfactory.decoderesource (Getresources (), r.drawable.appstore); Bitmap Alterbitmap=Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.getconfig ()); Canvas Canvas=NewCanvas (ALTERBITMAP); Paint Paint=NewPaint (); Paint.setcolor (Color.Black); //This is a synthetic form .Paint.setxfermode (NewPorterduffxfermode (Android.graphics.PorterDuff.Mode.DARKEN)); Canvas.drawbitmap (Bitmap,NewMatrix (), paint); Bitmap Ic_luncher=Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher); Canvas.drawbitmap (Ic_luncher,NewMatrix (), paint); Iv.setimagebitmap (ALTERBITMAP);
Here is the manual, we can open the API demos look at the effect:
Color processing
The color matrix is a 5x4 matrix that can be manipulated by the color matrix (ColorMatrix Class) in Android.
The operation rule of a matrix is that a row of matrix A is multiplied by a column of matrix C as a row of the Matrix R, the C matrix is the ARGB information contained in the picture, and the R matrix is a new color component that is applied to C with a color matrix, the result of which is as follows:
R ' = a*r + b*g + c*b + d*a + E;
G ' = f*r + g*g + h*b + i*a + j;
B ' = k*r + l*g + m*b + n*a + o;
A ' = p*r + q*g + r*b + s*a + t;
The color matrix is not as esoteric as it seems, in fact, there are very few parameters that need to be used, and the first line determines that the second row of Red determines the green third row determines the blue, the fourth row determines the transparency, and the fifth column is the offset of the color.
Bitmap =Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher); Alterbitmap=Bitmap.createbitmap (Bitmap.getwidth (), Bitmap.getheight (), Bitmap.getconfig ()); Canvas=NewCanvas (alterbitmap);p aint=NewPaint ();p aint.setcolor (color.black); matrix=NewMatrix ();FinalColorMatrix cm =NewColorMatrix ();p Aint.setcolorfilter (Newcolormatrixcolorfilter (cm)); Paint.setantialias (true); Canvas.drawbitmap (bitmap, matrix, paint); Iv.setimagebitmap (Alterbitmap); Sb1.setonseekbarchangelistener ( NewSeekbar.onseekbarchangelistener () {@Override Public voidOnstoptrackingtouch (SeekBar SeekBar) {intProgress =seekbar.getprogress (); System.out.println ("Progress1--->" +progress); Cm.set (New float[]{Progress/128.0f,0,0,0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,1,0 }); Paint.setcolorfilter (Newcolormatrixcolorfilter (cm)); Canvas.drawbitmap (bitmap, matrix, paint); Iv.setimagebitmap (ALTERBITMAP); }}
I'm the dividing line of the king of the Land Tiger.
Source code: HTTP://PAN.BAIDU.COM/S/1DD1QX01
Graphics compositing. zip
Graphics color processing. zip
Graphics transformations. zip
Reprint Please specify source: Http://www.cnblogs.com/yydcdut