Android image editing and processing (ii)

Source: Internet
Author: User

1. Input matrix:

The Matrix matrix class that you can use when drawing on an existing bitmap object or creating a bitmap from another bitmap object.

Each number of matrix matrices classes is applied to one of the 3 coordinates (x, y, or z) of each point on the image:

such as: 1, 0, 0,

0, 1, 0,

0, 0, 1

First line: Specify X coordinate: x=1x+0y+0z;

Second line: Specify the y-coordinate: y=0x+1y+oz;

Third line: Specify Z coordinate: z=0x+0y+1z;

                               Matrix matrix=new Matrix (); Matrix.setvalues (New float[]{1,0.5f,0,0,1,0,0,0,1}) Canvas.drawbitmap (BMP, Matrix, paint ); Copypicture.setimagebitmap (ALTEREDBITMAP);
When you need to increase the result, the bitmap size is set:

Alteredbitmap = Bitmap.createbitmap (Bmp.getwidth () * *, Bmp.getwidth (), Bmp.getconfig ());

Methods of the 2.Matrix class

(1) Rotation:

Matrix matrix=new Matrix ();

Matrix.setrotate (15);/* rotation angle, around the default point (0,0), positive number clockwise rotation, negative number counterclockwise rotation, the default point is the upper left corner of the image */
Matrix.setrotate (Bmp.getwidth ()/2,bmp.getheight ()/2);//Center rotation
Canvas.drawbitmap (BMP, Matrix, paint);

(2) Zoom:

Matrix.setscale (1.5f, 1);//zoom, the scale of the x-axis of the first parameter, and the scale of the y-axis of the second parameter.

(3) Pan:

Matrix.settranslate (1.5f,-10);//translation, the number of moves on the x-axis of the first parameter, and the number of moves in the y-axis of the second parameter.

(4) Image:

Matrix.setscale (-1, 1);
Matrix.posttranslate (Bmp.getwidth (), 0);//Move Right

(5) Flip:

Matrix.setscale (1,-1);
Matrix.posttranslate (0, Bmp.getheight ());//Move Down

(6) Draw an alternate image:

The disadvantage of the previously used method is that the image is truncated because the converted result size is not computed. WORKAROUND: When you first create a bitmap object, apply the matrix object instead of drawing to an empty bitmap object.

In this way, you don't need to get canvas and paint objects again. The disadvantage is that the bitmap object can no longer be changed.

There is a static method CreateBitmap in the bitmap class.

Bitmap.createbitmap (BMP, 0, 0, bmp.getwidth (), Bmp.getheight (), Matrix, false);//parameters are no longer described.

Example:

Matrix matrix=new Matrix (); Matrix.setrotate (Bmp.getwidth ()/2,bmp.getheight ()/2);//center rotation bitmap alteredbitmap= Bitmap.createbitmap (BMP, 0, 0, bmp.getwidth (), Bmp.getheight (), Matrix, false);
                                Copypicture.setimagebitmap (ALTEREDBITMAP);


Android image editing and processing (ii)

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.