Explorar el Código

自定义CropView完成

詹子聪 hace 5 años
padre
commit
42e843910d

+ 9 - 18
app/src/main/java/com/miekir/ocr/CameraActivity.java

@@ -5,7 +5,6 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.pm.ActivityInfo;
 import android.content.res.Configuration;
-import android.graphics.Bitmap;
 import android.graphics.ImageFormat;
 import android.graphics.Point;
 import android.graphics.SurfaceTexture;
@@ -32,7 +31,6 @@ import android.util.SparseIntArray;
 import android.view.Surface;
 import android.view.TextureView;
 import android.view.View;
-import android.view.ViewTreeObserver;
 import android.widget.Toast;
 
 import androidx.annotation.NonNull;
@@ -42,7 +40,7 @@ import com.miekir.ocr.base.BaseCameraActivity;
 import com.miekir.ocr.tool.CameraPreviewTool;
 import com.miekir.ocr.view.AutoFitTextureView;
 import com.miekir.ocr.view.GlideV4ImageEngine;
-import com.miekir.ocr.view.cropper.CropImageView;
+import com.miekir.ocr.view.PhotoCropView;
 import com.zhihu.matisse.Matisse;
 import com.zhihu.matisse.MimeType;
 
@@ -61,7 +59,7 @@ import java.util.concurrent.TimeUnit;
 
 import static android.os.Environment.DIRECTORY_PICTURES;
 
-public class CameraActivity extends BaseCameraActivity implements View.OnClickListener {
+public class CameraActivity extends BaseCameraActivity implements View.OnClickListener, PhotoCropView.onLocationListener {
     private static final int REQUEST_CODE_CHOOSE = 6;
     private CameraManager mCameraManager;
 
@@ -94,7 +92,6 @@ public class CameraActivity extends BaseCameraActivity implements View.OnClickLi
     private static final int MAX_PREVIEW_HEIGHT = 1080;
     private int mSensorOrientation;
 
-    private CropImageView civ_crop;
 
     private TextureView.SurfaceTextureListener textureListener = new TextureView.SurfaceTextureListener() {
         @Override
@@ -156,21 +153,10 @@ public class CameraActivity extends BaseCameraActivity implements View.OnClickLi
         textureView = findViewById(R.id.textureView);
         textureView.setSurfaceTextureListener(textureListener);
 
-        civ_crop = findViewById(R.id.civ_crop);
-        civ_crop.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
-            @Override
-            public void onGlobalLayout() {
-                civ_crop.getViewTreeObserver().removeOnGlobalLayoutListener(this);
-                //自定义裁剪-全屏的裁剪
-                Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
-                Bitmap bitmap = Bitmap.createBitmap(civ_crop.getWidth(), civ_crop.getHeight(), conf);
-                civ_crop.setImageBitmap(bitmap);
-            }
-        });
-
-
         findViewById(R.id.fl_take).setOnClickListener(this);
         findViewById(R.id.iv_album).setOnClickListener(this);
+        PhotoCropView pcv_scan = findViewById(R.id.pcv_scan);
+        pcv_scan.setLocationListener(this);
     }
 
 
@@ -520,4 +506,9 @@ public class CameraActivity extends BaseCameraActivity implements View.OnClickLi
             mSelected = Matisse.obtainResult(data);
         }
     }
+
+    @Override
+    public void locationRect(int startX, int startY, int endX, int endY) {
+        // 截取的区域坐标信息
+    }
 }

+ 39 - 0
app/src/main/java/com/miekir/ocr/tool/OverlayTool.java

@@ -0,0 +1,39 @@
+package com.miekir.ocr.tool;
+
+import com.miekir.ocr.view.cropper.CropImageOptions;
+import com.miekir.ocr.view.cropper.CropImageView;
+
+/**
+ * Copyright (C), 2019-2020, Genlot
+ *
+ * @author 詹子聪
+ * @date 2020/7/26 22:15
+ * Description: 遮罩层工具
+ */
+public class OverlayTool {
+    public static CropImageOptions getOverlayOptions() {
+        CropImageOptions options = new CropImageOptions();
+        options.fixAspectRatio = false;
+        options.aspectRatioX = 1;
+        options.aspectRatioY = 1;
+        options.scaleType = CropImageView.ScaleType.FIT_CENTER;
+        options.autoZoomEnabled = false;
+        options.multiTouchEnabled = false;
+        options.maxZoom = 1;
+        options.cropShape = CropImageView.CropShape.RECTANGLE;
+        options.guidelines = CropImageView.Guidelines.ON_TOUCH;
+        options.snapRadius = 9.0f;
+        options.touchRadius = 72.0f;
+        options.initialCropWindowPaddingRatio = 0.1f;
+        options.borderLineThickness = 0.0f;
+        options.borderCornerThickness = 6.0f;
+        options.borderCornerOffset = 0.0f;
+        options.guidelinesThickness = 0.0f;
+        options.showCropOverlay = true;
+        options.flipHorizontally = false;
+        options.flipVertically = false;
+        options.validate();
+
+        return options;
+    }
+}

+ 509 - 0
app/src/main/java/com/miekir/ocr/view/PhotoCropView.java

@@ -0,0 +1,509 @@
+package com.miekir.ocr.view;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.RectF;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.util.TypedValue;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.WindowManager;
+
+import com.miekir.ocr.R;
+
+public class PhotoCropView extends View {
+    public static final int SCAN_TYPE_EMAIL = 0;
+    public static final int SCAN_TYPE_ADDRESS_NAME = 1;
+    public static final int SCAN_TYPE_ALL = 2;
+    private static final String TAG = "PhotoCropView";
+
+    private onLocationListener locationListener;/*listen to the Rect */
+    private onChangeLocationlistener changeLocationlistener;/*listening position changed */
+
+    private int MODE;
+    private static final int MODE_OUTSIDE = 0x000000aa;/*170*/
+    private static final int MODE_INSIDE = 0x000000bb;/*187*/
+    private static final int MODE_POINT = 0X000000cc;/*204*/
+    private static final int MODE_ILLEGAL = 0X000000dd;/*221*/
+
+    private static final int minWidth = 150;/*the minimum width of the rectangle*/
+    private static final int minHeight = 250;/*the minimum height of the rectangle*/
+
+    private static final float EDGE_WIDTH = 1.8f;
+    private static final int ACCURACY = 35;/*touch accuracy*/
+
+    // 画角度的笔粗细
+    private static final float CORNER_STROKE = 6.0f;
+
+    private int pointPosition;/*vertex of a rectangle*/
+
+    private int sX;/*start X location*/
+    private int sY;/*start Y location*/
+    private int eX;/*end X location*/
+    private int eY;/*end Y location*/
+
+    private int pressX;/*X coordinate values while finger press*/
+    private int pressY;/*Y coordinate values while finger press*/
+
+    private int memonyX;/*the last time the coordinate values of X*/
+    private int memonyY;/*the last time the coordinate values of Y*/
+
+    private int coverWidth = 200;/*width of selection box*/
+    private int coverHeight = 400;/*height of selection box*/
+
+    private Paint mPaint;
+    private Paint mPaintLine;
+    private Paint mPaintCorner;
+    private Bitmap mBitmapCover;
+    private Bitmap mBitmapRectBlack;
+    private PorterDuffXfermode xfermode;/*paint mode*/
+
+    public PhotoCropView(Context context) {
+        this(context, null);
+    }
+
+    public PhotoCropView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public PhotoCropView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+
+        // 获取到宽高之后再初始化
+        post(() -> setScanArea(SCAN_TYPE_ALL));
+    }
+
+    /**
+     * 设置扫描区域
+     */
+    public void setScanArea(int scanType) {
+        switch (scanType) {
+            case SCAN_TYPE_EMAIL:
+                // 邮箱
+                coverWidth = (int) (getWidth()*0.815);
+                coverHeight = (int) (getWidth()*0.3);
+                sX = (getWidth()-coverWidth)/2;
+                sY = (int) (getWidth()*0.177);
+                break;
+            case SCAN_TYPE_ADDRESS_NAME:
+                coverWidth = (int) (getWidth()*0.815);
+                coverHeight = (int) (getWidth()*0.625);
+                sX = (getWidth()-coverWidth)/2;
+                sY = (getHeight()-coverHeight)/2;
+                break;
+            case SCAN_TYPE_ALL:
+                coverWidth = getWidth();
+                coverHeight = getHeight();
+                // 起始位置
+                sX = 0;
+                sY = 0;
+                break;
+            default:
+                coverWidth = (int) (getWidth()*0.815);
+                coverHeight = (int) (getWidth()*0.3);
+                // 起始位置
+                sX = (getWidth()-coverWidth)/2;
+                sY = (int) (getWidth()*0.177);
+                break;
+        }
+
+        init();
+    }
+
+    @SuppressWarnings("deprecation")
+    private void init() {
+
+        WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
+        int width = manager.getDefaultDisplay().getWidth();
+        int height = manager.getDefaultDisplay().getHeight();
+        // 遮罩的颜色
+        mBitmapCover = makeBitmap(width, height, getResources().getColor(R.color.black_transparent), 0, 0);
+        mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
+
+        eX = sX + coverWidth;
+        eY = sY + coverHeight;
+        pressX = 0;
+        pressY = 0;
+
+        xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
+
+        mPaint = new Paint();
+        mPaint.setAntiAlias(true);
+
+        mPaintLine = new Paint();
+        mPaintLine.setColor(Color.WHITE);
+        mPaintLine.setStrokeWidth(2.0f);
+
+        mPaintCorner = new Paint();
+        mPaintCorner.setColor(getContext().getResources().getColor(R.color.colorPrimary));
+        mPaintCorner.setStrokeWidth(CORNER_STROKE);
+    }
+
+    /*生成bitmap*/
+    private Bitmap makeBitmap(int mwidth, int mheight, int resource, int staX, int staY) {
+        Bitmap bm = Bitmap.createBitmap(mwidth, mheight, Bitmap.Config.ARGB_8888);
+        Canvas c = new Canvas(bm);
+        Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
+
+        p.setColor(resource);
+        c.drawRect(staX, staY, mwidth, mheight, p);
+        return bm;
+    }
+
+    /*@Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        mPaint.setFilterBitmap(false);
+        int sc = canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null,
+                Canvas.ALL_SAVE_FLAG);
+
+        canvas.drawBitmap(mBitmapCover, 0, 0, mPaint);
+        mPaint.setXfermode(xfermode);
+        canvas.drawBitmap(mBitmapRectBlack, sX, sY, mPaint);
+        if (locationListener != null) {
+            locationListener.locationRect(sX, sY, eX, eY);
+        }
+        mPaint.setXfermode(null);
+        canvas.restoreToCount(sc);
+        canvas.drawLine((float) sX - EDGE_WIDTH, (float) sY - EDGE_WIDTH, (float) eX + EDGE_WIDTH, (float) sY - EDGE_WIDTH, mPaintLine);//up
+        canvas.drawLine((float) sX - EDGE_WIDTH, (float) eY + EDGE_WIDTH, (float) eX + EDGE_WIDTH, (float) eY + EDGE_WIDTH, mPaintLine);//down
+        canvas.drawLine((float) sX - EDGE_WIDTH, (float) sY - EDGE_WIDTH, (float) sX - EDGE_WIDTH, (float) eY + EDGE_WIDTH, mPaintLine);//left
+        canvas.drawLine((float) eX + EDGE_WIDTH, (float) sY - EDGE_WIDTH, (float) eX + EDGE_WIDTH, (float) eY + EDGE_WIDTH, mPaintLine);//righ
+    }*/
+
+
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        mPaint.setFilterBitmap(false);
+        int sc = canvas.saveLayer(0, 0, canvas.getWidth(), canvas.getHeight(), null,
+                Canvas.ALL_SAVE_FLAG);
+
+        canvas.drawBitmap(mBitmapCover, 0, 0, mPaint);
+        mPaint.setXfermode(xfermode);
+        canvas.drawBitmap(mBitmapRectBlack, sX, sY, mPaint);
+        if (locationListener != null) {
+            locationListener.locationRect(sX, sY, eX, eY);
+        }
+        mPaint.setXfermode(null);
+        canvas.restoreToCount(sc);
+        //在此加入4个边角...
+        drawCorners(canvas);
+    }
+
+
+
+    /** Draw the corner of crop overlay. */
+    private void drawCorners(Canvas canvas) {
+        if (mPaintCorner != null) {
+            DisplayMetrics dm = Resources.getSystem().getDisplayMetrics();
+            //borderCornerThickness = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, dm);
+            float mBorderCornerLength = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, dm);
+
+            float lineWidth = 0;
+            float cornerWidth = mPaintCorner.getStrokeWidth();
+
+            // for rectangle crop shape we allow the corners to be offset from the borders
+            float w = 0;
+            RectF rect = new RectF(sX, sY, eX, eY);
+            rect.inset(w, w);
+
+            float cornerOffset = -CORNER_STROKE+2;
+            float cornerExtension = cornerWidth / 2 + cornerOffset;
+
+            // Top left
+            canvas.drawLine(
+                    rect.left - cornerOffset,
+                    rect.top - cornerExtension,
+                    rect.left - cornerOffset,
+                    rect.top + mBorderCornerLength,
+                    mPaintCorner);
+            canvas.drawLine(
+                    rect.left - cornerExtension,
+                    rect.top - cornerOffset,
+                    rect.left + mBorderCornerLength,
+                    rect.top - cornerOffset,
+                    mPaintCorner);
+
+            // Top right
+            canvas.drawLine(
+                    rect.right + cornerOffset,
+                    rect.top - cornerExtension,
+                    rect.right + cornerOffset,
+                    rect.top + mBorderCornerLength,
+                    mPaintCorner);
+            canvas.drawLine(
+                    rect.right + cornerExtension,
+                    rect.top - cornerOffset,
+                    rect.right - mBorderCornerLength,
+                    rect.top - cornerOffset,
+                    mPaintCorner);
+
+            // Bottom left
+            canvas.drawLine(
+                    rect.left - cornerOffset,
+                    rect.bottom + cornerExtension,
+                    rect.left - cornerOffset,
+                    rect.bottom - mBorderCornerLength,
+                    mPaintCorner);
+            canvas.drawLine(
+                    rect.left - cornerExtension,
+                    rect.bottom + cornerOffset,
+                    rect.left + mBorderCornerLength,
+                    rect.bottom + cornerOffset,
+                    mPaintCorner);
+
+            // Bottom left
+            canvas.drawLine(
+                    rect.right + cornerOffset,
+                    rect.bottom + cornerExtension,
+                    rect.right + cornerOffset,
+                    rect.bottom - mBorderCornerLength,
+                    mPaintCorner);
+            canvas.drawLine(
+                    rect.right + cornerExtension,
+                    rect.bottom + cornerOffset,
+                    rect.right - mBorderCornerLength,
+                    rect.bottom + cornerOffset,
+                    mPaintCorner);
+        }
+    }
+
+
+
+    @SuppressWarnings("NullableProblems")
+    @Override
+    public boolean onTouchEvent(MotionEvent event) {
+        switch (event.getAction()) {
+            case MotionEvent.ACTION_DOWN:
+                if (changeLocationlistener != null) {
+                    changeLocationlistener.locationChange("change self");
+                } else {
+                    changeLocationlistener = null;
+                }
+
+                memonyX = (int) event.getX();
+                memonyY = (int) event.getY();
+                checkMode(memonyX, memonyY);
+                break;
+            case MotionEvent.ACTION_MOVE: {
+                switch (MODE) {
+                    case MODE_ILLEGAL:
+                        pressX = (int) event.getX();
+                        pressY = (int) event.getY();
+                        recoverFromIllegal(pressX, pressY);
+                        postInvalidate();
+                        break;
+                    case MODE_OUTSIDE:
+                        //do nothing;
+                        break;
+                    case MODE_INSIDE:
+                        pressX = (int) event.getX();
+                        pressY = (int) event.getY();
+                        moveByTouch(pressX, pressY);
+                        postInvalidate();
+                        break;
+                    default:
+                        /*MODE_POINT*/
+                        pressX = (int) event.getX();
+                        pressY = (int) event.getY();
+                        mPaintLine.setColor(getContext().getResources().getColor(R.color.white));
+                        moveByPoint(pressX, pressY);
+                        postInvalidate();
+                        break;
+                }
+            }
+            break;
+            case MotionEvent.ACTION_UP:
+                mPaintLine.setColor(Color.WHITE);
+                postInvalidate();
+                break;
+            default:
+                break;
+        }
+        return true;
+    }
+
+    /*从非法状态恢复,这里处理的是达到最小值后能拉伸放大*/
+    private void recoverFromIllegal(int rx, int ry) {
+        if ((rx > sX && ry > sY) && (rx < eX && ry < eY)) {
+            MODE = MODE_ILLEGAL;
+        } else {
+            MODE = MODE_POINT;
+        }
+    }
+
+    private void checkMode(int cx, int cy) {
+        if (cx > sX+ACCURACY && cx < eX-ACCURACY && cy > sY+ACCURACY && cy < eY-ACCURACY) {
+            MODE = MODE_INSIDE;
+        } else if (nearbyPoint(cx, cy) < 4) {
+            MODE = MODE_POINT;
+        } else {
+            MODE = MODE_OUTSIDE;
+        }
+    }
+
+    /*推断点(inX,inY)是否靠近矩形的4个顶点*/
+    private int nearbyPoint(int inX, int inY) {
+        if ((Math.abs(sX - inX) <= ACCURACY && (Math.abs(inY - sY) <= ACCURACY))) {/*left-up angle*/
+            pointPosition = 0;
+            return 0;
+        }
+        if ((Math.abs(eX - inX) <= ACCURACY && (Math.abs(inY - sY) <= ACCURACY))) {/*right-up  angle*/
+            pointPosition = 1;
+            return 1;
+        }
+        if ((Math.abs(sX - inX) <= ACCURACY && (Math.abs(inY - eY) <= ACCURACY))) {/*left-down angle*/
+            pointPosition = 2;
+            return 2;
+        }
+        if ((Math.abs(eX - inX) <= ACCURACY && (Math.abs(inY - eY) <= ACCURACY))) {/*right-down angle*/
+            pointPosition = 3;
+            return 3;
+        }
+        pointPosition = 100;
+        return 100;
+    }
+
+    /*刷新矩形的坐标*/
+    private void refreshLocation(int isx, int isy, int iex, int iey) {
+        if (isx <= 0) {
+            this.sX = 0;
+        } else {
+            this.sX = isx;
+        }
+
+        if (isy <= 0) {
+            this.sY = 0;
+        } else {
+            this.sY = isy;
+        }
+
+        if (iex >= getWidth()) {
+            this.eX = getWidth();
+        } else {
+            this.eX = iex;
+        }
+
+        if (iey >= getHeight()) {
+            this.eY = getHeight();
+        } else {
+            this.eY = iey;
+        }
+
+    }
+
+    /*矩形随手指移动*/
+    private void moveByTouch(int mx, int my) {/*move center point*/
+        int dX = mx - memonyX;
+        int dY = my - memonyY;
+
+        if (!(eX == getWidth() && dX > 0)) {
+            sX += dX;
+        }
+
+        if (sX < 0) {
+            sX = 0;
+        }
+
+        if (!(eY == getHeight() && dY > 0)) {
+            sY += dY;
+        }
+        if (sY < 0) {
+            sY = 0;
+        }
+
+        eX = sX + coverWidth;
+        if (eX > getWidth()) {
+            eX = getWidth();
+        }
+        eY = sY + coverHeight;
+        if (eY > getHeight()) {
+            eY = getHeight();
+        }
+
+        memonyX = mx;
+        memonyY = my;
+
+    }
+
+    /*检測矩形是否达到最小值*/
+    private boolean checkLegalRect(int cHeight, int cWidth) {
+        return (cHeight > minHeight && cWidth > minWidth);
+    }
+
+    /*点击顶点附近时的缩放处理*/
+    @SuppressWarnings("SuspiciousNameCombination")
+    private void moveByPoint(int bx, int by) {
+        switch (pointPosition) {
+            case 0:/*left-up*/
+                coverWidth = Math.abs(eX - bx);
+                coverHeight = Math.abs(eY - by);
+                //noinspection SuspiciousNameCombination
+                if (!checkLegalRect(coverWidth, coverHeight)) {
+                    MODE = MODE_ILLEGAL;
+                } else {
+                    mBitmapRectBlack = null;
+                    mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
+                    refreshLocation(bx, by, eX, eY);
+                }
+                break;
+            case 1:/*right-up*/
+                coverWidth = Math.abs(bx - sX);
+                coverHeight = Math.abs(eY - by);
+                if (!checkLegalRect(coverWidth, coverHeight)) {
+                    MODE = MODE_ILLEGAL;
+                } else {
+                    mBitmapRectBlack = null;
+                    mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
+                    refreshLocation(sX, by, bx, eY);
+                }
+                break;
+            case 2:/*left-down*/
+                coverWidth = Math.abs(eX - bx);
+                coverHeight = Math.abs(by - sY);
+                if (!checkLegalRect(coverWidth, coverHeight)) {
+                    MODE = MODE_ILLEGAL;
+                } else {
+                    mBitmapRectBlack = null;
+                    mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
+                    refreshLocation(bx, sY, eX, by);
+                }
+                break;
+            case 3:/*right-down*/
+                coverWidth = Math.abs(bx - sX);
+                coverHeight = Math.abs(by - sY);
+                if (!checkLegalRect(coverWidth, coverHeight)) {
+                    MODE = MODE_ILLEGAL;
+                } else {
+                    mBitmapRectBlack = null;
+                    mBitmapRectBlack = makeBitmap(coverWidth, coverHeight, 0xff000000, coverWidth, coverHeight);
+                    refreshLocation(sX, sY, bx, by);
+                }
+                break;
+            default:
+                break;
+        }
+    }
+
+    public void setLocationListener(onLocationListener locationListener) {
+        this.locationListener = locationListener;
+    }
+
+    public interface onLocationListener {
+        public void locationRect(int startX, int startY, int endX, int endY);
+    }
+
+    public interface onChangeLocationlistener {
+        @SuppressWarnings("SameParameterValue")
+        public void locationChange(String msg);
+    }
+}

+ 4 - 3
app/src/main/java/com/miekir/ocr/view/rect/CustomLayout.java

@@ -5,6 +5,7 @@ import android.content.Context;
 import android.graphics.Path;
 import android.util.AttributeSet;
 import android.view.View;
+import android.view.ViewGroup;
 import android.widget.FrameLayout;
 
 import androidx.annotation.NonNull;
@@ -72,13 +73,13 @@ public class CustomLayout extends FrameLayout {
         if (view != null) {
             path = new Path();
             // 矩形透明区域
-            path.addRoundRect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom(), dp2Px(mContext,10), dp2Px(mContext,10),Path.Direction.CW);
+            path.addRoundRect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom(), 0, 0,Path.Direction.CW);
         }
         if (path != null) {
             background.setSrcPath(path);
         }
 
-        /*FrameLayout iv_scan = findViewById(R.id.iv_scan);
+        FrameLayout iv_scan = findViewById(R.id.iv_scan);
         iv_scan.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -87,7 +88,7 @@ public class CustomLayout extends FrameLayout {
                 params.height = 300;
                 iv_scan.requestLayout();
             }
-        });*/
+        });
     }
 
     public int dp2Px(Context context, float dp) {

+ 6 - 13
app/src/main/res/layout/activity_camera.xml

@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/activity_main"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -48,18 +47,12 @@
             android:orientation="vertical">
 
 
-            <com.miekir.ocr.view.cropper.CropImageView
-                android:id="@+id/civ_crop"
-                android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:layout_weight="4"
-                app:cropAutoZoomEnabled="false"
-                app:cropMaxZoom="1"/>
-            <!--<com.miekir.ocr.view.cropper.CropOverlayView
-                android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:layout_weight="4"/>-->
-
+             <!--灰色遮罩-->
+             <com.miekir.ocr.view.PhotoCropView
+                 android:id="@+id/pcv_scan"
+                 android:layout_width="match_parent"
+                 android:layout_height="0dp"
+                 android:layout_weight="4"/>
 
             <View
                 android:layout_width="match_parent"