|
8 | 8 | import android.hardware.Camera; |
9 | 9 | import android.os.Handler; |
10 | 10 | import android.support.annotation.UiThread; |
| 11 | +import android.support.annotation.WorkerThread; |
11 | 12 | import android.support.media.ExifInterface; |
12 | 13 |
|
13 | 14 | import java.io.ByteArrayInputStream; |
@@ -55,6 +56,19 @@ public static boolean hasCameraFacing(Context context, Facing facing) { |
55 | 56 | } |
56 | 57 |
|
57 | 58 |
|
| 59 | + /** |
| 60 | + * Decodes an input byte array and outputs a Bitmap that is ready to be displayed. |
| 61 | + * The difference with {@link android.graphics.BitmapFactory#decodeByteArray(byte[], int, int)} |
| 62 | + * is that this cares about orientation, reading it from the EXIF header. |
| 63 | + * |
| 64 | + * @param source a JPEG byte array |
| 65 | + */ |
| 66 | + @SuppressWarnings("WeakerAccess") |
| 67 | + @WorkerThread |
| 68 | + public static void decodeBitmap(final byte[] source) { |
| 69 | + decodeBitmap(source, Integer.MAX_VALUE, Integer.MAX_VALUE); |
| 70 | + } |
| 71 | + |
58 | 72 | /** |
59 | 73 | * Decodes an input byte array and outputs a Bitmap that is ready to be displayed. |
60 | 74 | * The difference with {@link android.graphics.BitmapFactory#decodeByteArray(byte[], int, int)} |
@@ -100,9 +114,21 @@ public void run() { |
100 | 114 | } |
101 | 115 |
|
102 | 116 |
|
| 117 | + /** |
| 118 | + * Decodes an input byte array and outputs a Bitmap that is ready to be displayed. |
| 119 | + * The difference with {@link android.graphics.BitmapFactory#decodeByteArray(byte[], int, int)} |
| 120 | + * is that this cares about orientation, reading it from the EXIF header. |
| 121 | + * |
| 122 | + * The image is also downscaled taking care of the maxWidth and maxHeight arguments. |
| 123 | + * |
| 124 | + * @param source a JPEG byte array |
| 125 | + * @param maxWidth the max allowed width |
| 126 | + * @param maxHeight the max allowed height |
| 127 | + */ |
103 | 128 | // TODO ignores flipping |
104 | 129 | @SuppressWarnings({"SuspiciousNameCombination", "WeakerAccess"}) |
105 | | - /* for tests */ static Bitmap decodeBitmap(byte[] source, int maxWidth, int maxHeight) { |
| 130 | + @WorkerThread |
| 131 | + public static Bitmap decodeBitmap(byte[] source, int maxWidth, int maxHeight) { |
106 | 132 | if (maxWidth <= 0) maxWidth = Integer.MAX_VALUE; |
107 | 133 | if (maxHeight <= 0) maxHeight = Integer.MAX_VALUE; |
108 | 134 | int orientation; |
|
0 commit comments