cookie-cutter
cookie-cutter copied to clipboard
Image getting not centered after select from gallery.
I have implemented your code in my class but my image is not getting centered. Instead of it is showing on right top.
As i have selected same image in your demo code then it is showing perfectly and properly but in my case it is not.
I have used same type of xml and java code of your in my class but nothing changed.
My Image:
In your demo showing proper with same image :
Hello, I managed to solve this problem, my solution was the following:
Instead of loading the image with Glide use the method that this default library brings, thus
Java: yourCookieCutterImageView.setImageBitmap(yourBitmap);
XML:
<com.adamstyrc.cookiecutter.CookieCutterImageView android:id="@+id/ivCrop" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/drawable_example"/>
I have also noticed that there is a way to place the smallest circle, in this way I managed to place a custom size in XML without losing the radius of the circle
Java: yourCookieCutterImageView.getParams().setCircleRadius(350);
Good Code :)
Sorry 2 years since the thread opened. Had the same issue today. I don't know exact issue.
- I used a default project it worked well.
- I used a Material Design library. It worked.
- When I tried in 3rd project with Material Library > It failed.
PROBLEM : The circle center was aligned with top left of screen.
SOLUTION : I fixed it using rotateBitmap function by 360 degrees.
RotateBitmap(bitmap, 360);
public static Bitmap RotateBitmap(Bitmap source, float angle) { Matrix matrix = new Matrix(); matrix.postRotate(angle); return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); }
Set the transformed bitmap again cookieCutterImageView.setBitmap(bitmap). It worked.