Image flip and Rotation
I tried to flip the image, but I still couldn't find a method. Find only one method to flip the image on the Internet
Resources res = This. getcontext (). getresources ();
IMG = bitmapfactory. decoderesource (Res, R. drawable. slogo );
Matrix matrix = new matrix ();
Matrix. postrotate (90);/* Flip 90 degrees */
Int width = IMG. getwidth ();
Int Height = IMG. getheight ();
R_img = bitmap. createbitmap (IMG, 0, 0, width, height, matrix, true );
Then you can directly import r_imgdraw to the canvas, for example:
Canvas. drawbitmap (a_img, 10, 10, P );
Easy to use ~~ It seems that many animation effects are also available in many system functions. Matrix is an important class for processing image effects such as flip and zoom.
Matrix. postscale: You can set the scaling ratio. The default value is 1.
Refer to the following code for image rotation during drawing:
Public void run (){
Int X0 = 50;
Int Y0 = 50;
Int x 1 = 200;
Int y2 = 200;
Canvas g;
Paint paint = new paint ();
Bitmap IMG = bitmap. createbitmap (x1-x0, y1-y0, bitmap. config. argb_8888 );
G = new canvas (IMG );
Paint. setcolor (color. Blue );
G. drawrect (New rectf (, x1-x0, y1-y0), paint );
Paint. setcolor (color. Red );
G. drawtext ("N", (x1-x0)/2, 10, paint );
G. drawtext ("W", 0, (y1-y0)/2, paint );
G. drawtext ("S", (x1-x0)/2, y1-y0, paint );
G. drawtext ("e", x1-x0-10, (y1-y0)/2, paint );
While (blrun)
{
G = holder. lockcanvas (); // obtain the canvas
Paint. setcolor (color. Red );
G. drawline (x0 + X1)/2,0, (x0 + X1)/2,480, paint );
G. drawline (0, (y0 + Y1)/2,320, (y0 + Y1)/2, paint );
G. Save ();
G. Rotate (180, (x0 + X1)/2, (y0 + Y1)/2 );
G. drawbitmap (IMG, x0, y0, paint );
Paint. setcolor (color. Blue );
G. Restore ();
G. drawline (320,480, paint );
Holder. unlockcanvasandpost (g); // unlock the canvas and submit the painted image
System. Out. println ("Run ");
}
}