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/y must be >= 0 #11

Open
martintoften opened this issue Apr 26, 2017 · 4 comments
Open

x/y must be >= 0 #11

martintoften opened this issue Apr 26, 2017 · 4 comments

Comments

@martintoften
Copy link

martintoften commented Apr 26, 2017

FATAL EXCEPTION: AsyncTask #3
                                                                        java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                            at android.os.AsyncTask$3.done(AsyncTask.java:325)
                                                                            at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                            at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                            at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
                                                                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                            at java.lang.Thread.run(Thread.java:761)
                                                                         Caused by: java.lang.IllegalArgumentException: x must be >= 0
                                                                            at android.graphics.Bitmap.checkXYSign(Bitmap.java:395)
                                                                            at android.graphics.Bitmap.createBitmap(Bitmap.java:731)
                                                                            at android.graphics.Bitmap.createBitmap(Bitmap.java:701)
                                                                            at com.steelkiwi.cropiwa.image.CropArea.applyCropTo(CropArea.java:35)
                                                                            at com.steelkiwi.cropiwa.image.CropImageTask.doInBackground(CropImageTask.java:49)
                                                                            at com.steelkiwi.cropiwa.image.CropImageTask.doInBackground(CropImageTask.java:20)
                                                                            at android.os.AsyncTask$2.call(AsyncTask.java:305)
                                                                            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
                                                                            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                            at java.lang.Thread.run(Thread.java:761) 

I have no way to catch this error :(
Can this be solved by catching the IllegalArgumentException in the AsyncTask, return it and call the onError method?

@smilecs
Copy link

smilecs commented Jun 8, 2017

I will suppose x to be width? have you tried checking what width is returned so compare and see first?

@longpham2310
Copy link

longpham2310 commented Jun 28, 2017

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);
    }

@zhangzhichaolove
Copy link

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.

@flasher297
Copy link
Contributor

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()));

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

Successfully merging a pull request may close this issue.

5 participants