mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Initial support for custom images scaling (#40)
This commit is contained in:
parent
c6ecfb2f67
commit
0c9bc97fe8
19 changed files with 127 additions and 91 deletions
|
@ -121,10 +121,14 @@ public class SubsamplingScaleImageView extends View {
|
|||
public static final int SCALE_TYPE_CENTER_INSIDE = 1;
|
||||
/** Scale the image uniformly so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view. The image is then centered in the view. */
|
||||
public static final int SCALE_TYPE_CENTER_CROP = 2;
|
||||
public static final int SCALE_TYPE_FIT_WIDTH = 3;
|
||||
public static final int SCALE_TYPE_FIT_HEIGHT = 4;
|
||||
public static final int SCALE_TYPE_ORIGINAL_SIZE = 5;
|
||||
/** Scale the image so that both dimensions of the image will be equal to or less than the maxScale and equal to or larger than minScale. The image is then centered in the view. */
|
||||
public static final int SCALE_TYPE_CUSTOM = 3;
|
||||
public static final int SCALE_TYPE_CUSTOM = 6;
|
||||
|
||||
private static final List<Integer> VALID_SCALE_TYPES = Arrays.asList(SCALE_TYPE_CENTER_CROP, SCALE_TYPE_CENTER_INSIDE, SCALE_TYPE_CUSTOM);
|
||||
|
||||
private static final List<Integer> VALID_SCALE_TYPES = Arrays.asList(SCALE_TYPE_CENTER_CROP, SCALE_TYPE_CENTER_INSIDE, SCALE_TYPE_CUSTOM, SCALE_TYPE_FIT_WIDTH, SCALE_TYPE_FIT_HEIGHT, SCALE_TYPE_ORIGINAL_SIZE);
|
||||
|
||||
// Bitmap (preview or full image)
|
||||
private Bitmap bitmap;
|
||||
|
@ -2003,12 +2007,20 @@ public class SubsamplingScaleImageView extends View {
|
|||
private float minScale() {
|
||||
int vPadding = getPaddingBottom() + getPaddingTop();
|
||||
int hPadding = getPaddingLeft() + getPaddingRight();
|
||||
if (minimumScaleType == SCALE_TYPE_CENTER_CROP) {
|
||||
return Math.max((getWidth() - hPadding) / (float) sWidth(), (getHeight() - vPadding) / (float) sHeight());
|
||||
} else if (minimumScaleType == SCALE_TYPE_CUSTOM && minScale > 0) {
|
||||
return minScale;
|
||||
} else {
|
||||
return Math.min((getWidth() - hPadding) / (float) sWidth(), (getHeight() - vPadding) / (float) sHeight());
|
||||
switch (minimumScaleType) {
|
||||
case SCALE_TYPE_CENTER_INSIDE:
|
||||
default:
|
||||
return Math.min((getWidth() - hPadding) / (float) sWidth(), (getHeight() - vPadding) / (float) sHeight());
|
||||
case SCALE_TYPE_CENTER_CROP:
|
||||
return Math.max((getWidth() - hPadding) / (float) sWidth(), (getHeight() - vPadding) / (float) sHeight());
|
||||
case SCALE_TYPE_FIT_WIDTH:
|
||||
return (getWidth() - hPadding) / (float) sWidth();
|
||||
case SCALE_TYPE_FIT_HEIGHT:
|
||||
return (getHeight() - vPadding) / (float) sHeight();
|
||||
case SCALE_TYPE_ORIGINAL_SIZE:
|
||||
return 1;
|
||||
case SCALE_TYPE_CUSTOM:
|
||||
return minScale;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue