Explorar el Código

较合理的参数

詹子聪 hace 5 años
padre
commit
8309efee3c

+ 28 - 6
app/src/main/java/com/miekir/ocr/ui/OperationPresenter.java

@@ -346,7 +346,29 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                 int croppedBitmapWidth;
                 int croppedBitmapHeight;
 
-                //boolean isLandscape = mBottom-mTop > mRight-mLeft;
+                // 经过试验,满屏宽总是与图片的宽完全对应,所以无论如何都要以宽为基准
+                if (rawBitmapWidth >= mWidth) {
+                    // 图片宽比屏幕的宽大,拿图片缩小,缩小为原宽除以pivot
+                    float pivot = 1.0f * rawBitmapWidth / mWidth;
+                    //float scaledHeight = rawBitmapHeight / pivot;
+                    //if (scaledHeight > )
+                    realLeft = (int) (mLeft * pivot);
+                    realTop = (int) (mTop * pivot);
+                    croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
+                    croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
+                } else {
+                    // 图片宽比屏幕的宽小,拿图片放大,放大为原宽乘以pivot
+                    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);
+                }
+
+
+
+
+                /*//boolean isLandscape = mBottom-mTop > mRight-mLeft;
 
                 // 图片宽度与屏幕宽度的比
                 float widthD = 1.0f * rawBitmapWidth / mWidth;
@@ -360,7 +382,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                         // 图片宽要缩小到屏幕宽
                         float pivot = 1.0f * rawBitmapWidth / mWidth;
                         realLeft = (int) (mLeft * pivot);
-                        realTop = (int) (mTop * pivot) + (rawBitmapHeight-mHeight)/2;
+                        realTop = (int) (mTop * pivot) + (int)(((rawBitmapHeight/pivot-mHeight)/2)*pivot);
                         croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
                         croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
                     } else {
@@ -377,8 +399,8 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                     if (heightD >= 1) {
                         // 以高为基准
                         // 图片高要缩小到屏幕高,缩小了pivot倍
-                        float pivot = 1.0f * rawBitmapHeight / mHeight;
-                        realLeft = (int) (mLeft * pivot) + (rawBitmapWidth-mWidth)/2;
+                        float pivot = 1.0f * rawBitmapWidth / mWidth;
+                        realLeft = (int) (mLeft * pivot) + (int)((rawBitmapWidth/pivot - mWidth)/2*pivot);
                         realTop = (int) (mTop * pivot);
                         croppedBitmapWidth = (int) ((mRight - mLeft) * pivot);
                         croppedBitmapHeight = (int) ((mBottom - mTop) * pivot);
@@ -391,7 +413,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                         croppedBitmapWidth = (int) (1.0f * (mRight - mLeft)/pivot);
                         croppedBitmapHeight = (int) (1.0f * (mBottom - mTop)/pivot);
                     }
-                }
+                }*/
 
 
                 Bitmap croppedBmp = Bitmap.createBitmap(normalBitmap, realLeft, realTop, croppedBitmapWidth, croppedBitmapHeight);
@@ -425,7 +447,7 @@ public class OperationPresenter extends BasePresenter<IOperationView> {
                 rotatedBitmap.recycle();
                 if (saveCropSuccess) {
                     File compressedFile = new Compressor(context.getApplicationContext())
-                            .setQuality(98)
+                            .setQuality(97)
                             .setDestinationDirectoryPath(file.getParentFile().getAbsolutePath())
                             .compressToFile(file, "cp_" + file.getName());
 

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

@@ -370,9 +370,9 @@ public class CameraInterface implements Camera.PreviewCallback {
             try {
                 mParams = mCamera.getParameters();
                 Camera.Size previewSize = CameraParamUtil.getInstance().getPreviewSize(mParams
-                        .getSupportedPreviewSizes(), 1800, screenProp);
+                        .getSupportedPreviewSizes(), 1000, screenProp);
                 Camera.Size pictureSize = CameraParamUtil.getInstance().getPictureSize(mParams
-                        .getSupportedPictureSizes(), 1800, screenProp);
+                        .getSupportedPictureSizes(), 2500, screenProp);
 
                 mParams.setPreviewSize(previewSize.width, previewSize.height);
 
@@ -383,10 +383,10 @@ public class CameraInterface implements Camera.PreviewCallback {
 
                 if (CameraParamUtil.getInstance().isSupportedFocusMode(
                         mParams.getSupportedFocusModes(),
-                        Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
+                        Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
                     //mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
                     // 自动对焦
-                    mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
+                    mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
                 }
 
                 if (CameraParamUtil.getInstance().isSupportedPictureFormats(mParams.getSupportedPictureFormats(),