Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provides synchronous version of decodeBitmap and adds annotation to m… #224

Merged
merged 2 commits into from
Jun 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -55,6 +56,19 @@ public static boolean hasCameraFacing(Context context, Facing facing) {
}


/**
* 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)}
Expand Down Expand Up @@ -100,9 +114,21 @@ public void run() {
}


/**
* 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;
Expand Down