naver / android-imagecropview

android image crop library
Apache License 2.0
254 stars 55 forks source link

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

Open O-liverQueen opened 7 years ago

O-liverQueen commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 5 years ago

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