mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-06-07 07:45:35 +01:00
Render images in a conversation true-to-size.
Previously, we were always rendering images as squares. Instead of doing that, we now render them as close to true-to-size as possible (within reasonable min/max width/height boundaries).
This commit is contained in:
committed by
Moxie Marlinspike
parent
9f8b4cf892
commit
ea374735e1
@@ -12,6 +12,7 @@ import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.*;
|
||||
import android.support.annotation.WorkerThread;
|
||||
import android.support.media.ExifInterface;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
@@ -131,6 +132,26 @@ public class BitmapUtil {
|
||||
return options;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Pair<Integer, Integer> getExifDimensions(InputStream inputStream) throws IOException {
|
||||
ExifInterface exif = new ExifInterface(inputStream);
|
||||
int width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
|
||||
int height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
|
||||
if (width == 0 && height == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
|
||||
if (orientation == ExifInterface.ORIENTATION_ROTATE_90 ||
|
||||
orientation == ExifInterface.ORIENTATION_ROTATE_270 ||
|
||||
orientation == ExifInterface.ORIENTATION_TRANSVERSE ||
|
||||
orientation == ExifInterface.ORIENTATION_TRANSPOSE)
|
||||
{
|
||||
return new Pair<>(height, width);
|
||||
}
|
||||
return new Pair<>(width, height);
|
||||
}
|
||||
|
||||
public static Pair<Integer, Integer> getDimensions(InputStream inputStream) throws BitmapDecodingException {
|
||||
BitmapFactory.Options options = getImageDimensions(inputStream);
|
||||
return new Pair<>(options.outWidth, options.outHeight);
|
||||
|
||||
Reference in New Issue
Block a user