Simple restrictions on the border for android image enlargement and reduction

Source: Internet
Author: User

Simple restrictions on the border for android image enlargement and reduction
Simple restrictions on the border for android image enlargement and reduction
First of all, you need to understand that even such an outstanding software is not perfect for processing the 4-boundary limitation. You can zoom in and zoom out the image at the upper boundary. Therefore, if you are stuck on this issue and the project progress is affected, do not tangle for too long.
Secondly, the effect I want to achieve in this article is that when an image is pulled over a boundary, the boundary position is automatically returned. Do not talk nonsense, go to the Code:

@ Override public boolean onTouch (View v, MotionEvent event) {/** retain the last eight motionevents through the operation. ACTION_MASK = 255 */switch (event. getAction () & MotionEvent. ACTION_MASK) {case MotionEvent. ACTION_UP: // exit MyLogger by finger. e (TAG, ACTION_UP: + mode); // reset the image PointF p1 = getLeftPointF (); PointF p2 = getRightPointF (); // reset the left boundary if (p1.x> 0) matrix. postTranslate (-p1.x, 0); // reset the right boundary if (p2.x
 
  
MImgPic. getHeight () {// reset the upper boundary if (p1.y> 0) matrix. postTranslate (0,-p1.y); // reset the lower boundary if (p2.y <mImgPic. getHeight () matrix. postTranslate (0, mImgPic. getHeight ()-p2.y);} else {float row = (mImgPic. getHeight ()-(p2.y-p1.y)/2; matrix. postTranslate (0, row-p1.y);} break;} return true ;}
 
This event is triggered as long as a finger is removed from the screen .. No matter how many of you are already on the screen.
The figure above has two key methods .. This algorithm is used to locate two points in the upper left corner and lower right corner of an image .. You can use it directly. Why. I will explain it later.
// Obtain the upper coordinate of the image. private PointF getLeftPointF () {Rect rectTemp = mImgPic. getDrawable (). getBounds (); float [] values = new float [9]; matrix. getValues (values); float leftX = values [2]; float leftY = values [5]; MyLogger. e (TAG, coordinate in the upper left corner: x + leftX + y + leftY); return new PointF (leftX, leftY);} // obtain the coordinate of the image. private PointF getRightPointF () {Rect rectTemp = mImgPic. getDrawable (). getBounds (); float [] values = new float [9]; matrix. getValues (values); float leftX = values [2] + rectTemp. width () * values [0]; float leftY = values [5] + rectTemp. height () * values [4]; MyLogger. e (TAG, coordinate in the lower right corner: x + leftX + y + leftY); return new PointF (leftX, leftY );}


First, there is such a pit B diagram (rrrrrrrrrrrrrrrrrrrrrrrrr)
This B Chart is just a mocking of a person with poor mathematics, right .. Okay, everyone is scared.

MSCALE is used to process scaling

MSKEW is used to handle the error tangent transformation.

MTRANS is used to process translation.



It's a dog .. I'm afraid readers may be upset.
Big point.

Drag, it is obvious that it is MTRANS !!... Float values = float [9 ];
Array Storage
The storage matrix is: the first row is 123, the second row is 456, And the last row is 789.
First, let's look at the points in the upper left corner:
I got it directly.

Values [2] values [5]
This does not explain.
In the lower right corner, it is easy to think. Directly add images
The size is good !!!
The problem is that the image size changes after the image is zoomed in and out!

Generally, the first response is to write one by yourself. Calculate and store image changes. Obviously, it is effort-consuming and thankless. Low Efficiency ..... At first, I thought
The authors of matrix in this pitfall are quite confused. Since the current graph is not directly available
Coordinate Method. I should have never thought of recording the changes in the image .. However
Then I found out that I was wrong .... The person who writes this program is a math shopping.
Currency ......

Yes




MSCALE is used to process the ratio of scaling ----
(And the ratio to the initial image )!


So the formula for coordinates in the lower right corner came out.
float leftX= values[2]+rectTemp.width()*values[0];        float leftY=values[5]+rectTemp.height()*values[4];

Don't worry about the pitfalls of B !!

 

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.