update readme

pull/1/head
Dylan McIntyre 8 years ago
parent 8154e129f4
commit fec44ff7e7
  1. BIN
      .repo/permissions.gif
  2. 2
      camerakit/src/main/java/com/flurgle/camerakit/CameraView.java
  3. 29
      camerakit/src/main/java/com/flurgle/camerakit/utils/CenterCrop.java
  4. 17
      demo/src/main/res/layout/activity_main.xml

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 3.1 MiB

@ -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 {

@ -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) {

@ -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">
<ImageButton
android:id="@+id/capturePhoto"
@ -54,7 +54,8 @@
android:layout_weight="1"
android:backgroundTint="@color/colorPrimary"
android:src="@drawable/ic_video"
android:tint="@android:color/white" />
android:tint="@android:color/white"
android:visibility="gone" />
<ImageButton
android:id="@+id/toggleFlash"
@ -166,21 +167,21 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:checkedButton="@+id/modeCropVisible"
android:checkedButton="@+id/modeCropFullSize"
android:orientation="horizontal">
<RadioButton
android:id="@+id/modeCropVisible"
android:id="@+id/modeCropFullSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop to visible" />
android:text="Full size" />
<RadioButton
android:id="@+id/modeCropFullSize"
android:id="@+id/modeCropVisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Full size" />
android:text="Crop to visible" />
</RadioGroup>

Loading…
Cancel
Save