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