ArthurHub / Android-Image-Cropper

Image Cropping Library for Android, optimized for Camera / Gallery.
Apache License 2.0
6.39k stars 1.37k forks source link

java.lang.IllegalArgumentException: width/height must be > 0 #137

Open devappmin opened 8 years ago

devappmin commented 8 years ago

On some device, when I do Bitmap bitmap = cropImageView.getCroppedImage() Then It makes illegalargumentexception like

java.lang.RuntimeException: Failed to load sampled bitmap: content://media/external/images/media/31373 width must be > 0 at com.theartofdev.edmodo.cropper.BitmapUtils.cropBitmap(BitmapUtils.java:218) at com.theartofdev.edmodo.cropper.CropImageView.getCroppedImage(CropImageView.java:566) at com.theartofdev.edmodo.cropper.CropImageView.getCroppedImage(CropImageView.java:544) at com.petabyte.composewatch.Activity.CropActivity.onOptionsItemSelected(CropActivity.java:71) at android.app.Activity.onMenuItemSelected(Activity.java:3205) at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:421) at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:188) at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:103) at android.support.v7.app.AppCompatDelegateImplV7.onMenuItemSelected(AppCompatDelegateImplV7.java:663) at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:810) at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152) at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:957) at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:947) at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618) at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:155) at android.view.View.performClick(View.java:5698) at android.widget.TextView.performClick(TextView.java:10855) at android.view.View$PerformClick.run(View.java:22565) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7230) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by: java.lang.IllegalArgumentException: width must be > 0 at android.graphics.Bitmap.checkWidthHeight(Bitmap.java:443) at android.graphics.Bitmap.createBitmap(Bitmap.java:822) at com.theartofdev.edmodo.cropper.BitmapUtils.cropBitmap(BitmapUtils.java:158) at com.theartofdev.edmodo.cropper.BitmapUtils.cropBitmap(BitmapUtils.java:214)

Do you know why it occur?

ArthurHub commented 8 years ago

That is strange... need more data: Do you use the latest version? looks like you do but I want to make sure. Do you use fixed aspect ratio? if so what is it? Can you reproduce it or you see it from production? Do you know on which devices it happens?

devappmin commented 8 years ago

Yeah, I use latest version. and I used fixed aspect to getWindowManager().getDefaultDisplay().getWidth(), getWindowManager().getDefaultDisplay().getHeight() And it worked perfect when I used cropimageactivity.

I used CropImageActivity before, but I want to rotate aspectradio instead of the picture. So I made my on Activity with CropImageView

ArthurHub commented 8 years ago

I don't know how it can happen :disappointed: Don't even know what to tell you... you can try the latest version and debug to find more clues...

ArthurHub commented 8 years ago

Well... if it happens again or someone else has this issue please reopen it.

thomasfischersm commented 7 years ago

I get the same error or the wrong area cropped. I have a repro and cause identified here: https://github.com/edmodo/cropper/issues/134

DHosseiny commented 5 years ago

@ArthurHub This is happen when use negetive rotation and call getCroppedImage after it. using negative rotation corrupts rotate rectangle.

Andrec-Dxs commented 4 years ago

Any updates on this issue?

axelasa commented 3 years ago

Hello there @ArthurHub I'm facing the same issue but my project is on OpenCV with kotlin see below

Screenshot 2021-07-06 at 15 57 00
axelasa commented 3 years ago

the line complaining is 47