Open martintoften opened 7 years ago
I will suppose x to be width? have you tried checking what width is returned so compare and see first?
I make it workaround like this.
public Bitmap applyCropTo(Bitmap bitmap) {
int x = findRealCoordinate(bitmap.getWidth(), cropRect.left, imageRect.width());
int y = findRealCoordinate(bitmap.getHeight(), cropRect.top, imageRect.height());
int width = findRealCoordinate(bitmap.getWidth(), cropRect.width(), imageRect.width());
int height = findRealCoordinate(bitmap.getHeight(), cropRect.height(), imageRect.height());
if (x < 0) {
x = 0;
}
if (y + height >= bitmap.getHeight()) {
y = bitmap.getHeight() - height;
}
Log.d(TAG, "x/y/with/height : " + x + "/" + y + "/" + width + "/" + height);
Bitmap immutableCropped = Bitmap.createBitmap(bitmap,
x,
y,
width,
height);
return immutableCropped.copy(immutableCropped.getConfig(), true);
}
CropImageTask -> doInBackground -> IOException changed to catch (Exception e) { Return e; }
CropArea -> applyCropTo (Bitmap bitmap) -> changed to public Bitmap applyCropTo (Bitmap bitmap) throws IllegalArgumentException
Above can prevent crashes.
CropIwaView -> preceded by judgment: crop (CropIwaSaveConfig saveConfig) { If (imageView.getImageRect (). Left == -1 || imageView.getImageRect (). Left == 0) { Return; } } If the crop method has not yet completed, it will be returned, of course, here you can do other operating logic.
I've fixed this issue with posting message on UI thread. It seems that this exception is raised when sixe of view is still not set.
cropView.post(() ->
cropView.crop(new CropIwaSaveConfig.Builder(croppedFileDestination)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.setQuality(80)
.build()));
I have no way to catch this error :( Can this be solved by catching the
IllegalArgumentException
in theAsyncTask
, return it and call theonError
method?