Double-click the Android Gallery image magnification algorithm,

Source: Internet
Author: User

Double-click the Android Gallery image magnification algorithm,
Double-click magnification of an image is related to the image size, view size, and current scale size.
To avoid image enlargement, the maximum limit SCALE_LIMIT of a magnification is set. Currently, this value is 4.
The specific algorithm is as follows:
The image width and height are recorded as: imageW imageH
The view width and height of the displayed image are respectively recorded as viewW viewH.
Several important proportions are recorded as follows:

scale_1 = viewW / imageW;scale_2 = viewH / imageH;scale_3 = viewW / imageH;scale_4 = viewH / imageW;

If the aspect ratio of the current image is greater than 2 or <0.5, zoomRate is calculated as follows:

(1) Current scale = min (scale_1, scale_2 );
(2) zoomRate = min (max (scale_1, scale_2), max (scale_3, scale_4 ));
(3) If zoomRate> SCALE_LIMIT, zoomRate = SCALE_LIMIT;
(4) If scale> = zoomRate, the result of (1) is retained and the zoomRate value is recalculated from step (2). Otherwise, the value is jumped to (6)
ZoomRate = max (scale_1, scale_2), max (scale_3, scale_4 ));
(5) If zoomRate> SCALE_LIMIT, zoomRate = SCALE_LIMIT;

(6) The zoomRate value is a multiple of the image size.


If the aspect ratio of the current image is <= 2 or> = 0.5, zoomRate is calculated as follows:
(1) Current scale = min (scale_1, scale_2 );
(2) largerInitRate = max (min (scale_1, scale_2), min (scale_3, scale_4 ));
(3) If largerInitRate> SCALE_LIMIT, then largerInitRate = SCALE_LIMIT;
(4) zoomRate = min (scale_2, largerInitRate * 2.0f );
(5) If zoomRate> SCALE_LIMIT, zoomRate = SCALE_LIMIT;
(6) If scale> = zoomRate, the result of the first three steps will be retained, and the zoomRate value will be recalculated from step (4); otherwise, it will jump to (8)
ZoomRate = largerInitRate * 2.0f;
(7) If zoomRate> SCALE_LIMIT, zoomRate = SCALE_LIMIT;

(8) The zoomRate value is a multiple of the image size.


Reprinted please indicate the source: Zhou mu Shui CSDN blog http://blog.csdn.net/zhoumushui

My GitHub: Zhou mu Shui's GitHub https://github.com/zhoumushui





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.