Crop code analysis

Source: Internet
Author: User

// Grows the cropping rectange by (dx, Dy) in image space. <br/> void growby (float dx, float Dy) {<br/> If (mmaintainaspectratio) {<br/> If (dx! = 0) {<br/> DY = dx/minitialaspectratio; <br/>} else if (dy! = 0) {<br/> dx = Dy * minitialaspectratio; <br/>}< br/> // don't let the cropping rectangle grow too fast. <br/> // grow at most half of the difference between the image rectangle and <br/> // The cropping rectangle. <br/> rectf r = new rectf (mcroprect); <br/> If (dx> 0f & R. width () + 2 * DX> mimagerect. width () {<br/> float adjustment = (mimagerect. width ()-R. width ()/2f; <br/> DX = Adjustment; <br/> If (mmaintainaspectratio) {<br/> DY = dx/minitialaspectratio; <br/>}< br/> If (dy> 0f & R. height () + 2 * dy> mimagerect. height () {<br/> float adjustment = (mimagerect. height ()-R. height ()/2f; <br/> DY = adjustment; <br/> If (mmaintainaspectratio) {<br/> dx = Dy * minitialaspectratio; <br/>}< br/> r. inset (-dx,-dy); <br/> // don't let the cropping Rectangle shrink too fast. <br/> final float widthcap = 25f; <br/> If (R. width () <widthcap) {<br/> r. inset (-(widthcap-R. width ()/2f, 0f); <br/>}< br/> float heightcap = mmaintainaspectratio <br/>? (Widthcap/minitialaspectratio) <br/>: widthcap; <br/> If (R. height () <peightcap) {<br/> r. inset (0f,-(heightcap-R. height ()/2f); <br/>}< br/> // put the cropping rectangle inside the image rectangle. <br/> If (R. left <mimagerect. left) {<br/> r. offset (mimagerect. left-R. left, 0f); <br/>} else if (R. right> mimagerect. right) {<br/> r. offset (-(R. right-mimagerect. right), 0); <br/>}< br/> If (R. top <mimagerect. top) {<br/> r. offset (0f, mimagerect. top-R. top); <br/>} else if (R. bottom> mimagerect. bottom) {<br/> r. offset (0f,-(R. bottom-mimagerect. bottom); <br/>}< br/> mcroprect. set (r); <br/> mdrawrect = computelayout (); <br/> mcontext. invalidate (); <br/>}

Mcroprect. offset (dx, Dy); // At the beginning, the offset is so much. There are so many Dx and Dy.

// Put the cropping rectangle inside image rectangle.

Mcroprect. offset (
Math. Max (0, mimagerect. Left-mcroprect. Left ),
Math. Max (0, mimagerect. Top-mcroprect. Top ));

//

Because mimagerect. Top-mcroprect. Top <= 0 indicates moving internally.

Mimagerect. Top-mcroprect. Top> = 0. It indicates that mcroprect has been removed from the corresponding mimagerect. Top-mcroprect. Top, which is based on the original one. Mcroprect. Top + (mimagerect. Top-mcroprect. Top) --> ensure that it is internal.

 

Mcroprect. offset (
Math. Min (0, mimagerect. Right-mcroprect. Right ),
Math. Min (0, mimagerect. Bottom-mcroprect. Bottom ));

 

Offset to control the movement of the mcroprect area.

 

// Grows the cropping rectange by (dx, Dy) in image space. <br/> void moveBy (float dx, float Dy) {<br/> rect invalrect = new rect (mdrawrect); <br/> mcroprect. offset (dx, Dy); <br/> // put the cropping rectangle inside image rectangle. <br/> mcroprect. offset (<br/> math. max (0, mimagerect. left-mcroprect. left), <br/> math. max (0, mimagerect. top-mcroprect. top); <br/> mcroprect. offset (<br/> math. min (0, mimagerect. right-mcroprect. right), <br/> math. min (0, mimagerect. bottom-mcroprect. bottom); <br/> mdrawrect = computelayout (); <br/> invalrect. union (mdrawrect); <br/> invalrect. inset (-10,-10); <br/> mcontext. invalidate (invalrect); <br/>} 

 

 

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.