Skip to content

Commit a6740da

Browse files
committed
Use single calculation with computing sample size
1 parent 604e9c7 commit a6740da

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

app/src/main/java/com/github/mobile/util/ImageUtils.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,11 @@ public static Bitmap getBitmap(final byte[] image, int sampleSize) {
103103
* @return scale
104104
*/
105105
public static int getScale(Point size, int width, int height) {
106-
int currWidth = size.x;
107-
int currHeight = size.y;
108-
109-
int scale = 1;
110-
while (currWidth >= width || currHeight >= height) {
111-
currWidth /= 2;
112-
currHeight /= 2;
113-
scale *= 2;
114-
}
115-
return scale;
106+
if (size.x > width || size.y > height)
107+
return Math.max(Math.round((float) size.y / (float) height),
108+
Math.round((float) size.x / (float) width));
109+
else
110+
return 1;
116111
}
117112

118113
/**

0 commit comments

Comments
 (0)