* commit 'ec7ffa145572eae2566cb1c763bcf50d8d1e8d6b': Displaying Bitmaps Efficiently Training - Fix inSampleSize selection
This commit is contained in:
Binary file not shown.
@@ -110,12 +110,17 @@ public static int calculateInSampleSize(
|
|||||||
int inSampleSize = 1;
|
int inSampleSize = 1;
|
||||||
|
|
||||||
if (height > reqHeight || width > reqWidth) {
|
if (height > reqHeight || width > reqWidth) {
|
||||||
if (width > height) {
|
|
||||||
inSampleSize = Math.round((float)height / (float)reqHeight);
|
// Calculate ratios of height and width to requested height and width
|
||||||
} else {
|
final int heightRatio = Math.round((float) height / (float) reqHeight);
|
||||||
inSampleSize = Math.round((float)width / (float)reqWidth);
|
final int widthRatio = Math.round((float) width / (float) reqWidth);
|
||||||
}
|
|
||||||
|
// Choose the smallest ratio as inSampleSize value, this will guarantee
|
||||||
|
// a final image with both dimensions larger than or equal to the
|
||||||
|
// requested height and width.
|
||||||
|
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
return inSampleSize;
|
return inSampleSize;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|||||||
Reference in New Issue
Block a user