Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image getting not centered after select from gallery. #9

Open
PGAndroid opened this issue Dec 15, 2017 · 2 comments
Open

Image getting not centered after select from gallery. #9

PGAndroid opened this issue Dec 15, 2017 · 2 comments

Comments

@PGAndroid
Copy link

PGAndroid commented Dec 15, 2017

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

@ederdoski
Copy link

ederdoski commented Jun 22, 2018

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

@niazaliahmed
Copy link

niazaliahmed commented Aug 15, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants