Flip and rotate images in Android

Source: Internet
Author: User
Tags drawtext image flip

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 ");
}
 
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.