詹子聪 6 лет назад
Родитель
Сommit
8327efe914

+ 11 - 5
app/src/main/java/com/miekir/ocr/MainActivity.java

@@ -6,12 +6,12 @@ import android.content.Intent;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Bundle;
+import android.view.ViewTreeObserver;
 
 import androidx.annotation.Nullable;
 import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AppCompatActivity;
 
-import com.miekir.common.utils.SizeTool;
 import com.miekir.ocr.view.cropper.CropImageView;
 import com.tbruyelle.rxpermissions2.RxPermissions;
 
@@ -81,9 +81,15 @@ public class MainActivity extends AppCompatActivity {
     private void getUri(Uri uri) {
         CropImageView cropImageView = findViewById(R.id.cropImageView);
         //cropImageView.setImageUriAsync(uri);
-        //自定义裁剪-全屏的裁剪
-        Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
-        Bitmap bitmap = Bitmap.createBitmap(SizeTool.SCREEN_WIDTH, SizeTool.SCREEN_HEIGHT, conf);
-        cropImageView.setImageBitmap(bitmap);
+        cropImageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+            @Override
+            public void onGlobalLayout() {
+                cropImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
+                //自定义裁剪-全屏的裁剪
+                Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
+                Bitmap bitmap = Bitmap.createBitmap(cropImageView.getWidth(), cropImageView.getHeight(), conf);
+                cropImageView.setImageBitmap(bitmap);
+            }
+        });
     }
 }

+ 4 - 4
app/src/main/java/com/miekir/ocr/view/cropper/CropOverlayView.java

@@ -599,12 +599,12 @@ public class CropOverlayView extends View {
 
     float left = Math.max(BitmapUtils.getRectLeft(mBoundsPoints), 0);
     // 自定义裁剪-顶部无间隙
-    float top = 0;
-    //float top = Math.max(BitmapUtils.getRectTop(mBoundsPoints), 0);
+    //float top = 0;
+    float top = Math.max(BitmapUtils.getRectTop(mBoundsPoints), 0);
     float right = Math.min(BitmapUtils.getRectRight(mBoundsPoints), getWidth());
     // 自定义裁剪-底部无间隙
-    float bottom = getHeight();
-    //float bottom = Math.min(BitmapUtils.getRectBottom(mBoundsPoints), getHeight());
+    //float bottom = getHeight();
+    float bottom = Math.min(BitmapUtils.getRectBottom(mBoundsPoints), getHeight());
 
     if (mCropShape == CropImageView.CropShape.RECTANGLE) {
       if (!isNonStraightAngleRotated() || Build.VERSION.SDK_INT <= 17) {

+ 9 - 17
app/src/main/res/layout/activity_camera.xml

@@ -1,5 +1,6 @@
 <?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"
@@ -38,16 +39,9 @@
 
         <com.miekir.ocr.view.AutoFitTextureView
             android:id="@+id/textureView"
-            android:layout_width="wrap_content"
+            android:layout_width="match_parent"
             android:layout_height="match_parent" />
 
-
-
-
-
-
-
-
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
@@ -58,25 +52,25 @@
                 android:id="@+id/civ_crop"
                 android:layout_width="match_parent"
                 android:layout_height="0dp"
-                android:layout_weight="4"/>
+                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"/>-->
 
 
+            <View
+                android:layout_width="match_parent"
+                android:layout_height="0.8dp"
+                android:background="@color/white"/>
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="0dp"
                 android:layout_weight="3"
                 android:orientation="vertical"
                 android:background="@color/black_transparent">
-
-                <View
-                    android:layout_width="match_parent"
-                    android:layout_height="0.8dp"
-                    android:background="@color/white"/>
-
                 <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
@@ -248,7 +242,5 @@
                 </LinearLayout>
             </LinearLayout>
         </LinearLayout>
-
-
     </FrameLayout>
 </LinearLayout>

+ 22 - 4
app/src/main/res/layout/activity_main.xml

@@ -1,13 +1,31 @@
 <?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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">
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:background="@color/white">
+
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="50dp"/>
     <com.miekir.ocr.view.cropper.CropImageView
         android:id="@+id/cropImageView"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="4"
         app:cropAutoZoomEnabled="false"/>
 
-</RelativeLayout>
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="3dp"/>
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="0dp"
+        android:layout_weight="3"
+        android:background="@android:color/black"/>
+    <FrameLayout
+        android:layout_width="match_parent"
+        android:layout_height="3dp"/>
+</LinearLayout>