From 810323aefa7f0c7a1a5e7bda04c1dc799fd7f32d Mon Sep 17 00:00:00 2001 From: Josh Burton Date: Fri, 1 Jun 2018 07:16:21 +1200 Subject: [PATCH] Provides synchronous version of decodeBitmap and adds annotation to make it clear this should run on a worker thread Closes #221 --- .../otaliastudios/cameraview/CameraUtils.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cameraview/src/main/utils/com/otaliastudios/cameraview/CameraUtils.java b/cameraview/src/main/utils/com/otaliastudios/cameraview/CameraUtils.java index a81870f7..23dbbcdd 100644 --- a/cameraview/src/main/utils/com/otaliastudios/cameraview/CameraUtils.java +++ b/cameraview/src/main/utils/com/otaliastudios/cameraview/CameraUtils.java @@ -8,6 +8,7 @@ import android.graphics.Matrix; import android.hardware.Camera; import android.os.Handler; import android.support.annotation.UiThread; +import android.support.annotation.WorkerThread; import android.support.media.ExifInterface; import java.io.ByteArrayInputStream; @@ -55,6 +56,20 @@ public class CameraUtils { } + /** + * Decodes an input byte array and outputs a Bitmap that is ready to be displayed. + * The difference with {@link android.graphics.BitmapFactory#decodeByteArray(byte[], int, int)} + * is that this cares about orientation, reading it from the EXIF header. + * This is executed in a background thread, and returns the result to the original thread. + * + * @param source a JPEG byte array + */ + @SuppressWarnings("WeakerAccess") + @WorkerThread + public static void decodeBitmap(final byte[] source) { + decodeBitmap(source, Integer.MAX_VALUE, Integer.MAX_VALUE); + } + /** * Decodes an input byte array and outputs a Bitmap that is ready to be displayed. * The difference with {@link android.graphics.BitmapFactory#decodeByteArray(byte[], int, int)} @@ -102,7 +117,8 @@ public class CameraUtils { // TODO ignores flipping @SuppressWarnings({"SuspiciousNameCombination", "WeakerAccess"}) - /* for tests */ static Bitmap decodeBitmap(byte[] source, int maxWidth, int maxHeight) { + @WorkerThread + public static Bitmap decodeBitmap(byte[] source, int maxWidth, int maxHeight) { if (maxWidth <= 0) maxWidth = Integer.MAX_VALUE; if (maxHeight <= 0) maxHeight = Integer.MAX_VALUE; int orientation;