From 819638862fce349018506d7d2b0b92d284036e43 Mon Sep 17 00:00:00 2001 From: Josh Burton Date: Fri, 1 Jun 2018 12:18:52 +1200 Subject: [PATCH] Provides synchronous version of decodeBitmap (#224) * Provides synchronous version of decodeBitmap and adds annotation to make it clear this should run on a worker thread Closes #221 * Tidies up decodeBitmap javadoc --- .../otaliastudios/cameraview/CameraUtils.java | 28 ++++++++++++++++++- 1 file changed, 27 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..dd7a74e2 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,19 @@ 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. + * + * @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)} @@ -100,9 +114,21 @@ 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. + * + * The image is also downscaled taking care of the maxWidth and maxHeight arguments. + * + * @param source a JPEG byte array + * @param maxWidth the max allowed width + * @param maxHeight the max allowed height + */ // 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;