Ok, so I'll try my best to explain my problem. I have used this code to get a "screenshot" of my FrameLayout
/**
* Function that takes a screenshot of the view passed and returns a bitmap for it.
*
* @param view {@link View}
* @return screenshot of the view passed
*/
public Bitmap screenShot(View view) {
Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
Here is my FrameLayout
<FrameLayout
android:id="@+id/frame_layout_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/photoImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />
<com.my.android.util.DrawCustomView
android:id="@+id/draw_custom_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
DrawCustomView
is used to paint on photoImageView
.
Now I also have different activity to crop image. So, I saved this bitmap (using screenshot(view)
) in a file and send the file path to this crop activity. In my crop activity I am using https://github.com/ArthurHub/Android-Image-Cropper library's CropImageView
to crop the image.
When I try to crop the painted photo sent to crop activity I get a weird crop, something like this :
The image doubles on cropping too much : https://drive.google.com/open?id=0B4jK5QX65b0ZSHdMTWIzZXluZXc
Before zooming in : https://drive.google.com/open?id=0B4jK5QX65b0ZeUk3NUlGUHRSQ0E
This is how a normal picture appears in crop activity : https://drive.google.com/open?id=0B4jK5QX65b0ZNk9oSG1ZaGxYOVk
I also notice that the bounds for cropping are restricted to image size in the normal case but when edited using screenshot(), the bounds take the size of the screen.
I have tested my crop activity beforehand and it works fine for images sent from camera. I also tried to send a picture that is not obtained using screenshot function, and it worked fine in crop activity.
I'll be happy to provide more info, any help is much appreciated... I am relatively new to android development :)
EDIT
This video might give more perspective to the problem https://drive.google.com/open?id=0B4jK5QX65b0ZSUVFZDlQeTc4QnM
You can try this method to capture a screenshot of your view.
You can call this method like
YourUtilsClass.captureScreenShotAndSave(mContext, mViewToCapture);