mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 00:31:54 +00:00
committed by
Moxie Marlinspike
parent
5116c61f43
commit
f72cd5b0ff
@@ -133,17 +133,11 @@ public class BitmapUtil {
|
||||
final int imageWidth = options.outWidth;
|
||||
final int imageHeight = options.outHeight;
|
||||
|
||||
int scaler = 1;
|
||||
int scaleFactor = (constrainedMemory ? 1 : 2);
|
||||
while ((imageWidth / scaler / scaleFactor >= maxWidth) && (imageHeight / scaler / scaleFactor >= maxHeight)) {
|
||||
scaler *= 2;
|
||||
}
|
||||
|
||||
options.inSampleSize = scaler;
|
||||
options.inSampleSize = getScaleFactor(imageWidth, imageHeight, maxWidth, maxHeight, constrainedMemory);
|
||||
options.inJustDecodeBounds = false;
|
||||
|
||||
BufferedInputStream is = new BufferedInputStream(data);
|
||||
Bitmap roughThumbnail = BitmapFactory.decodeStream(is, null, options);
|
||||
InputStream is = new BufferedInputStream(data);
|
||||
Bitmap roughThumbnail = BitmapFactory.decodeStream(is, null, options);
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ioe) {
|
||||
@@ -189,6 +183,20 @@ public class BitmapUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting static int getScaleFactor(int inWidth, int inHeight,
|
||||
int maxWidth, int maxHeight,
|
||||
boolean constrained)
|
||||
{
|
||||
int scaler = 1;
|
||||
while (!constrained && ((inWidth / scaler / 2 >= maxWidth) && (inHeight / scaler / 2 >= maxHeight))) {
|
||||
scaler *= 2;
|
||||
}
|
||||
while (constrained && ((inWidth / scaler > maxWidth) || (inHeight / scaler > maxHeight))) {
|
||||
scaler *= 2;
|
||||
}
|
||||
return scaler;
|
||||
}
|
||||
|
||||
private static Bitmap fixOrientation(Bitmap bitmap, InputStream orientationStream) {
|
||||
final int orientation = Exif.getOrientation(orientationStream);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user