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

x and y offset is not giving correct values. #21

Open
O-liverQueen opened this issue Feb 8, 2017 · 3 comments
Open

x and y offset is not giving correct values. #21

O-liverQueen opened this issue Feb 8, 2017 · 3 comments

Comments

@O-liverQueen
Copy link

Hi,

I am trying to get the x and y offset when i cropped the image, the value what i am getting from CropInfo Class is different than the actual result.

First i am getting the CropInfo object and getting all the values, and then i am using your same formula to calculate x and y i-e this
float x = Math.abs(viewImageLeft - cropLeft) / scale;
float y = Math.abs(viewImageTop - cropTop) / scale;

I think this x and y values is giving me the result for scaled bitmap, how can i get the original x and y offset after cropping??

Please help me.

@helloyako
Copy link
Contributor

hello @O-liverQueen

Too large bitmap can't load on memory.
so I resize original image just before crop

https://github.com/naver/android-imagecropview/blob/master/imagecropview/src/main/java/com/naver/android/helloyako/imagecrop/model/CropInfo.java#L33-L35

If your image under 4000 * 4000, module doesn't resize.(same original bitmap)

please check bitmap width
https://github.com/naver/android-imagecropview/blob/master/imagecropview/src/main/java/com/naver/android/helloyako/imagecrop/model/CropInfo.java#L47

thank you :)

@O-liverQueen
Copy link
Author

Hello @helloyako

I got the requirement to crop the image and send the image with x and y offset,

I was able to select and crop image, but the x & y offset position was not correct, the values which i was getting was of the cropped image, which is returned in getCroppedImage() method of CropView Class.

After doing all the calculation, i came up with this this formula, which gives you the exact x and y offset of the original image, not for the cropped image.

FOR X-AXIS:
float xAxis = (originalImageWidth / info.getViewBitmapWidth());
xAxis= Math.abs(xAxis* (info.getViewImageLeft() - info.getCropLeft())) / info.getScale();

FOR Y-AXIS:
float yAxis = (imageHeights / info.getViewBitmapHeight());
yAxis= Math.abs(yAxis* (info.getViewImageTop() - info.getCropTop())) / info.getScale();

where info is your CropInfo Object.

@arpitjoshi08
Copy link

@O-liverQueen any solution? i have also same issue

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