diff --git a/.repo/permissions.gif b/.repo/permissions.gif
index ed77de72..79916a36 100644
Binary files a/.repo/permissions.gif and b/.repo/permissions.gif differ
diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
index 834f4b96..34f6446f 100644
--- a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
+++ b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
@@ -405,6 +405,8 @@ public class CameraView extends FrameLayout {
public void onPictureTaken(byte[] jpeg) {
super.onPictureTaken(jpeg);
if (mCropOutput) {
+ int width = mPictureMode == PICTURE_MODE_QUALITY ? mCameraImpl.getCaptureSize().getWidth() : mCameraImpl.getPreviewSize().getWidth();
+ int height = mPictureMode == PICTURE_MODE_QUALITY ? mCameraImpl.getCaptureSize().getHeight() : mCameraImpl.getPreviewSize().getHeight();
AspectRatio outputRatio = AspectRatio.of(getWidth(), getHeight());
getCameraListener().onPictureTaken(new CenterCrop(jpeg, outputRatio).getJpeg());
} else {
diff --git a/camerakit/src/main/java/com/flurgle/camerakit/utils/CenterCrop.java b/camerakit/src/main/java/com/flurgle/camerakit/utils/CenterCrop.java
index eb08fbd6..e7a88fd3 100644
--- a/camerakit/src/main/java/com/flurgle/camerakit/utils/CenterCrop.java
+++ b/camerakit/src/main/java/com/flurgle/camerakit/utils/CenterCrop.java
@@ -2,10 +2,13 @@ package com.flurgle.camerakit.utils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.BitmapRegionDecoder;
import android.graphics.Rect;
import android.graphics.YuvImage;
+import android.util.Log;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
public class CenterCrop {
@@ -19,12 +22,26 @@ public class CenterCrop {
}
public CenterCrop(byte[] jpeg, AspectRatio targetRatio) {
- Bitmap bitmap = BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length);
- Rect crop = getCrop(bitmap.getWidth(), bitmap.getHeight(), targetRatio);
- bitmap = Bitmap.createBitmap(bitmap, crop.left, crop.top, crop.width(), crop.height());
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
- this.croppedJpeg = out.toByteArray();
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inJustDecodeBounds = true;
+ BitmapFactory.decodeByteArray(jpeg, 0, jpeg.length, options);
+
+ Rect crop = getCrop(options.outWidth, options.outHeight, targetRatio);
+ try {
+ Bitmap bitmap = BitmapRegionDecoder.newInstance(
+ jpeg,
+ 0,
+ jpeg.length,
+ true
+ ).decodeRegion(crop, null);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
+ this.croppedJpeg = out.toByteArray();
+ } catch (IOException e) {
+ Log.e("CameraKit", e.toString());
+ return;
+ }
}
private static Rect getCrop(int currentWidth, int currentHeight, AspectRatio targetRatio) {
diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml
index fd9c7991..b1822ebf 100644
--- a/demo/src/main/res/layout/activity_main.xml
+++ b/demo/src/main/res/layout/activity_main.xml
@@ -18,7 +18,7 @@
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_gravity="center_horizontal"
- app:ckCropOutput="true"
+ app:ckCropOutput="false"
app:ckFacing="back"
app:ckFlash="off"
app:ckPictureMode="quality"
@@ -34,7 +34,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
- android:weightSum="4">
+ android:weightSum="3">
+ android:tint="@android:color/white"
+ android:visibility="gone" />
+ android:text="Full size" />
+ android:text="Crop to visible" />