"Android Get started ten" draw pictures and picture rotation

Source: Internet
Author: User

Let's start with a brief description of the drawing:

Due to Canvas.drawbitmap (bitmap, SRC, DST, paint), there are four parameters so there are roughly four or five steps.

1, through the GetResource () method to get the Bitmapdrawable type object in the Drawable folder

2. Convert the bitmapdrawable type to an object of type bitmap

3, create SRC, DST, two rectangles, SRC refers to the original graphics truncated pictures, DST refers to the target location of the rectangle.

4, the picture of the brush is generally null.

5. Call Canvas.drawbitmap (bitmap, SRC, DST, paint) method.

It then shows how to rotate the picture:

Primarily through matrix matrices.

1. Creating a Matrix Object

2. Determine the direction of rotation

3. Canvas Set Matrix

Note : Any graphics in the canvas after Canvas.setmatrix (matrix) will rotate.

When you finish drawing the image you want to rotate, call Canvas.setmatrix (null), and cancel the rotation of the canvas.


Instance code:

/* * Insert Picture */bitmapdrawable drawable = (bitmapdrawable) getresources (). getdrawable (R.drawable.girls); Bitmap Bitmap = Drawable.getbitmap (); Rect src = new rect (0,0,440,320); Rect dst = new rect (Maxleft, MaxUp, Maxright, Maxbottom); Matrix matrix = new Matrix (matrix.setrotate, 0, 0), Canvas.setmatrix (Matrix), Canvas.drawbitmap (bitmap, SRC, DST, NULL);//canvas.setmatrix (null);
Thank you ~

"Android Get started ten" draw pictures and picture rotation

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.