I am trying to crop the image within the rectangle as image attachedI'm able to take and crop the picture. But the cropped image is not of same position. I don't want to use crop images library
This is picture taken
This is cropped image, which i'm getting
This is my layout file
<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>
This is how i'm doing this
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);