Browse Source

较合理的参数

詹子聪 5 năm trước cách đây
mục cha
commit
9be8a23462

+ 29 - 26
app/src/main/java/com/miekir/ocr/ui/OperationPresenter.java

@@ -354,15 +354,17 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                 float heightD = 1.0f * rawBitmapHeight / mHeight;
                 boolean isPortraitPhoto = BigDecimal.valueOf(heightD).compareTo(BigDecimal.valueOf(widthD)) > 0;
                 if (isPortraitPhoto) {
-                    // 高的倍距大,以高为基准
-                    if (heightD > 1) {
+                    // 高的倍距大
+                    if (widthD >= 1) {
+                        // 以宽为基准
                         // 图片宽要缩小到屏幕宽
-                        float pivot = 1.0f * rawBitmapHeight / mHeight;
+                        float pivot = 1.0f * rawBitmapWidth / mWidth;
                         realLeft = (int) (mLeft * pivot);
-                        realTop = (int) (mTop * pivot);
+                        realTop = (int) (mTop * pivot) + (rawBitmapHeight-mHeight)/2;
                         croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
                         croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
                     } else {
+                        // 以高为基准
                         // 屏幕高要缩小到图片高
                         float pivot = 1.0f * mHeight / rawBitmapHeight;
                         realLeft = (int) (mLeft / pivot);
@@ -371,23 +373,24 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                         croppedBitmapHeight = (int) (1.0f * (mBottom - mTop) / pivot);
                     }
                 } else {
-                    // 宽的倍距大,以宽为基准
-//                    if (widthD > 1) {
-//                        // 图片高要缩小到屏幕高
-//                        float pivot = 1.0f * rawBitmapWidth / mWidth;
-//                        realLeft = (int) (mLeft * pivot);
-//                        realTop = (int) (mTop * pivot);
-//                        croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
-//                        croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
-//                    } else {
-//
-//                    }
-                    // 屏幕宽要缩小到图片宽
-                    float pivot = 1.0f * mWidth / rawBitmapWidth;
-                    realLeft = (int) (mLeft/pivot);
-                    realTop = (int) (mTop/pivot);
-                    croppedBitmapWidth = (int) (1.0f * (mRight - mLeft)/pivot);
-                    croppedBitmapHeight = (int) (1.0f * (mBottom - mTop)/pivot);
+                    // 宽的倍距大
+                    if (heightD >= 1) {
+                        // 以高为基准
+                        // 图片高要缩小到屏幕高,缩小了pivot倍
+                        float pivot = 1.0f * rawBitmapHeight / mHeight;
+                        realLeft = (int) (mLeft * pivot) + (rawBitmapWidth-mWidth)/2;
+                        realTop = (int) (mTop * pivot);
+                        croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
+                        croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
+                    } else {
+                        // 以宽为基准
+                        // 屏幕宽要缩小到图片宽
+                        float pivot = 1.0f * mWidth / rawBitmapWidth;
+                        realLeft = (int) (mLeft/pivot);
+                        realTop = (int) (mTop/pivot);
+                        croppedBitmapWidth = (int) (1.0f * (mRight - mLeft)/pivot);
+                        croppedBitmapHeight = (int) (1.0f * (mBottom - mTop)/pivot);
+                    }
                 }
 
 
@@ -407,11 +410,11 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                 }
                 int max = rotatedBitmap.getWidth() > rotatedBitmap.getHeight() ? rotatedBitmap.getWidth() : rotatedBitmap.getHeight();
                 float multi = 1.0f;
-                if (max > 2000) {
-                    multi = 1.0f * max / 2000 + 0.4f;
-                } else if (multi > 1800) {
-                    multi = 1.1f;
-                }
+//                if (max > 2000) {
+//                    multi = 1.0f * max / 2000 + 0.4f;
+//                } else if (multi > 1800) {
+//                    multi = 1.1f;
+//                }
 
                 // 压缩图片
                 boolean saveCropSuccess = ImageUtil.saveBitmapFile(rotatedBitmap, file, multi);

+ 16 - 5
camera/src/main/java/com/cjt2325/cameralibrary/CameraInterface.java

@@ -39,6 +39,9 @@ import java.util.ArrayList;
 import java.util.List;
 
 import static android.graphics.Bitmap.createBitmap;
+import static android.hardware.Camera.Parameters.ANTIBANDING_AUTO;
+import static android.hardware.Camera.Parameters.SCENE_MODE_AUTO;
+import static android.hardware.Camera.Parameters.WHITE_BALANCE_AUTO;
 
 /**
  * =====================================
@@ -367,9 +370,9 @@ public class CameraInterface implements Camera.PreviewCallback {
             try {
                 mParams = mCamera.getParameters();
                 Camera.Size previewSize = CameraParamUtil.getInstance().getPreviewSize(mParams
-                        .getSupportedPreviewSizes(), 1900, screenProp);
+                        .getSupportedPreviewSizes(), 1800, screenProp);
                 Camera.Size pictureSize = CameraParamUtil.getInstance().getPictureSize(mParams
-                        .getSupportedPictureSizes(), 1900, screenProp);
+                        .getSupportedPictureSizes(), 1800, screenProp);
 
                 mParams.setPreviewSize(previewSize.width, previewSize.height);
 
@@ -385,14 +388,22 @@ public class CameraInterface implements Camera.PreviewCallback {
                     // 自动对焦
                     mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                 }
+
                 if (CameraParamUtil.getInstance().isSupportedPictureFormats(mParams.getSupportedPictureFormats(),
                         ImageFormat.JPEG)) {
                     mParams.setPictureFormat(ImageFormat.JPEG);
                     mParams.setJpegQuality(100);
                 }
-                //mParams.setExposureCompensation(0);
-                //mParams.setAntibanding(ANTIBANDING_AUTO);
-                //mParams.setSceneMode(SCENE_MODE_AUTO);
+
+
+                mParams.setExposureCompensation(0);
+                //mParams.setColorEffect(EFFECT_POSTERIZE);
+                //mParams.setColorEffect(EFFECT_SEPIA);
+                mParams.setAntibanding(ANTIBANDING_AUTO);
+                mParams.setWhiteBalance(WHITE_BALANCE_AUTO);
+                mParams.setSceneMode(SCENE_MODE_AUTO);
+
+
                 mCamera.setParameters(mParams);
                 mParams = mCamera.getParameters();
                 mCamera.setPreviewDisplay(holder);  //SurfaceView

+ 3 - 1
camerax/src/main/java/com/miekir/camerax/MainActivity.java

@@ -1,4 +1,6 @@
-package com.miekir.camerax;//saus: https://codelabs.developers.google.com/codelabs/camerax-getting-started/
+package com.miekir.camerax;
+//saus: https://codelabs.developers.google.com/codelabs/camerax-getting-started/
+// https://github.com/android/camera-samples/tree/master/CameraXBasic
 
 import android.content.pm.PackageManager;
 import android.graphics.Matrix;