jayrambhia / CropperNoCropper

Instagram Style Image Cropper for Android (Library)
http://www.jayrambhia.com/project/nocropper-library
Apache License 2.0
475 stars 99 forks source link

Prescale issue #24

Closed yu-t closed 6 years ago

yu-t commented 7 years ago

With prescale enabled the cropping is working wrong.

jayrambhia commented 7 years ago

Hi @yu-t Thanks for reporting the issue. Could you give me some more details so that I can reproduce it and fix it? Thanks.

yu-t commented 7 years ago

@jayrambhia When I set an image as cropped to center (or any other scale, except fit to center), then after cropping it crops wrong (it saves not the same area that was visible in preview). I assume this is because of the logic in the getCroppedBitmap() method. It should be changed to something like this:

if (doPreScaling) {
            float currScaleX = getMatrixValue(matrix, Matrix.MSCALE_X);
            float currScaleY = getMatrixValue(matrix, Matrix.MSCALE_Y);
            matrix.postScale(1 / (mPreScale * currScaleX), 1 / (mPreScale * currScaleY));
}

As the scale is changed during the cropToCenter() and it's not 1.

jayrambhia commented 7 years ago

@yu-t I can reproduce the issue. Could you tell me what are you using preScaling for? It has always been a half baked feature. This is the time I decide whether to fix it or remove it. I have not used that feature. And due to lack of documentation, I don't remember the exact reason I put it in the first place.

yu-t commented 7 years ago

@jayrambhia I'm using it because I need to work with large images (more than 1280). And in order to display them without OutOfMemoryError it should be prescaled for preview. But the crop and save options should be applied to the original image for better quality. That's why I need it :)

jayrambhia commented 7 years ago

@yu-t That's a good use case. I think I had something similar in mind when I was trying it out. I don't think the current approach works. And it will use more RAM as original bitmap is also kept in the memory. I was thinking, to make this work, when the user sets a high res image with preScaling, the cropper will resize it and not store the original image (Just the scale of the original image). And when the user wants to crop, it will give a Rect which you can pass along with a bitmap to a utility function provided by the cropper which would give you the cropped bitmap. What do you think?

yu-t commented 7 years ago

@jayrambhia I think it's a good solution. And it seems to be working with this change in getCroppedBitmap():

if (doPreScaling) {
            float currScaleX = getMatrixValue(matrix, Matrix.MSCALE_X);
            float currScaleY = getMatrixValue(matrix, Matrix.MSCALE_Y);
            matrix.postScale(1 / (mPreScale * currScaleX), 1 / (mPreScale * currScaleY));
}
jayrambhia commented 6 years ago

Fixed in 0.3.0