我正在尝试在矩形框内裁剪图片,如所附图像。我能够拍摄和裁剪图片。但裁剪后的图片位置不同。我不想使用裁剪图片库。
这是拍摄的照片
这是我获得的裁剪图像: 这是我的布局文件。<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.android.camera2basic.AutoFitTextureView
android:id="@+id/texture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="@+id/rectangle"
android:layout_width="300dp"
android:layout_height="200dp"
android:background="@drawable/rectangle"
android:layout_centerInParent="true"></RelativeLayout>
<FrameLayout
android:id="@+id/control"
android:layout_width="match_parent"
android:layout_height="112dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">
<Button
android:id="@+id/picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/picture" />
</FrameLayout>
这是我正在进行的方式
Rect rectf = new Rect();
//For coordinates location relative to the screen/display
relativeLayout.getGlobalVisibleRect(rectf);
Bitmap croppedBitmap = Bitmap.createBitmap(origBitmap, rectf.left, rectf.top, rectf.width(), rectf.height(), null, false);