react-native-image-resizer icon indicating copy to clipboard operation
react-native-image-resizer copied to clipboard

Bitmap.getWidth() on null object Refference

Open feriyalsusanto opened this issue 9 years ago • 9 comments

Hi,

I got this error when createResizedImage screenshot_20161018-150447 1

and my code: ImageResizer.createResizedImage(source.uri, 800, 600, 'JPEG', 80) {....} where source.uri is from ImagePicker.

Thanks

feriyalsusanto avatar Oct 18 '16 08:10 feriyalsusanto

I am running into the same issue.

Monte9 avatar Oct 22 '16 02:10 Monte9

I'm getting the problem too, but I assume your source.uri is wrong as well as mine. Will test if it's null, because I'm inputing a base64 string as the image.

mafelix avatar Oct 25 '16 21:10 mafelix

same here, some time image resize successfully, so not sure what went wrong

14795880_10154135086158163_1757021924_o png

leoabacade avatar Oct 27 '16 05:10 leoabacade

I got same issue.It's work on iOS,but not work on Android.

"dependencies": { "base-64": "^0.1.0", "react": "15.3.2", "react-native": "0.36.0", "react-native-device-info": "^0.9.6", "react-native-image-picker": "^0.22.12", "realm": "^0.14.3" },

2016-11-01 2 21 17

Here is the log:

11-01 15:34:51.516 27082-27099/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules Process: com.engineertools_rn, PID: 27082 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at fr.bamlab.rnimageresizer.ImageResizer.rotateImage(ImageResizer.java:63) at fr.bamlab.rnimageresizer.ImageResizer.createResizedImage(ImageResizer.java:231) at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImageWithExceptions(ImageResizerModule.java:49) at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImage(ImageResizerModule.java:37) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:318) at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:148) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196) at java.lang.Thread.run(Thread.java:818)

dyguests avatar Nov 01 '16 04:11 dyguests

[Android] It seems happened on Bitmap scaledImage = ImageResizer.resizeImage(sourceImage, newWidth, newHeight); return null,and then call rotatedImage = ImageResizer.rotateImage(scaledImage, rotation);

I think it happens when imagePath is a url,not a file path(sourceImage = BitmapFactory.decodeFile(imagePath, options); )

maybe..?!?

(And it won't happen on iOS)

[http://stackoverflow.com/questions/8992964/android-load-from-url-to-bitmap](a way to load image from url.)

It not work on base64?

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: data:image/jpeg;base64,/9j/4TaJRXhpZgAATU0AKgAAAAg ...
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
                                                       at fr.bamlab.rnimageresizer.ImageResizer.rotateImage(ImageResizer.java:63)
                                                       at fr.bamlab.rnimageresizer.ImageResizer.createResizedImage(ImageResizer.java:231)
                                                       at fr.bamlab.rnimageresizer.ImageResizerModule.createResizedImageWithExceptions(ImageResizerModule.java:49)

dyguests avatar Nov 03 '16 07:11 dyguests

Hey guys, thanks for reporting this issue! It would be awesome if you could make a sample project (use this one: https://github.com/bamlab/react-native-image-resizer/tree/master/example) and tell what to do next (for example: run react-native run-android, click there and boom!) to reproduce the bug. It would speed up the bug hunt a lot for me! I'll be happy to fix the issue then! :D

cc @dyguests @leoabacade @Monte9 @mafelix @feriyalsusanto

4ian avatar Nov 03 '16 23:11 4ian

@4ian Aleady fixed.The newest code can resize a base64 uri,

ImageResizer.loadBitmapFromBase64(imagePath);

But the published lib on npm("react-native-image-resizer": "0.0.11") can not resize a base64 uri.

Waiting for the new publish version. (anyway to add something like loadBitmapFromUrl(???)) Thanks..... :)

dyguests avatar Nov 04 '16 02:11 dyguests

Oops I totally forgot that latest changes were not published on npm. That's fixed with version 0.0.12 :) I'll close the issue if someone can confirm that it's working with this new version.

4ian avatar Nov 05 '16 21:11 4ian

Not tested with base64, but still happening for URIs on some devices, but its happening randomly, sometimes it works 10x in row and then crash

Nodonisko avatar Feb 01 '19 10:02 Nodonisko

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 01 '22 19:09 stale[bot]

This issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Sep 09 '22 03:09 stale[bot]