cookie-cutter icon indicating copy to clipboard operation
cookie-cutter copied to clipboard

Image getting not centered after select from gallery.

Open PGAndroid opened this issue 7 years ago • 2 comments

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:

screenshot_2017-12-15-11-29-13

In your demo showing proper with same image :

screenshot_2017-12-15-11-29-28

PGAndroid avatar Dec 15 '17 06:12 PGAndroid

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 :)

ederdoski avatar Jun 22 '18 22:06 ederdoski

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.

niazaliahmed avatar Aug 15 '20 20:08 niazaliahmed