RaananW / PhoneGap-Image-Resizer

Providing an image resizer plugin for phonegap projects on both Android and iOS
93 stars 89 forks source link

Image Resize function not working on Android #15

Closed imhassan closed 9 years ago

imhassan commented 9 years ago

Hi, I am calling "window.imageResizer.resizeImage()" with fileURL and storeImage = true. But it crashed android app, gives a popup message " Unfortunately app stopped working". I have used many options but unable to resize the image. Below are my recent options that I have tried.

        window.imageResizer.resizeImage(function(success_resp) {
            utils.debug('success, img re-size: ' + JSON.stringify(success_resp));
            callback(success_resp);
        }, function(fail_resp) {
            utils.debug('fail, img re-size: ' + JSON.stringify(fail_resp));
            // callback(fail_resp);
        }, img_path, $scope.order.category.width2, 0, {
            imageDataType : ImageResizer.IMAGE_DATA_TYPE_URL,
            resizeType : ImageResizer.RESIZE_TYPE_PIXEL,
            pixelDensity:true,
            storeImage : true,
            photoAlbum : false,
            filename : img_path.substr(img_path.lastIndexOf("/") + 1),
            format : 'jpg'
        });
RaananW commented 9 years ago

Hi,

Been a while since I worked in it, I'll try debugging it during the weekend and see why it happens. Mind saying what versions of phonegap/cordova and android you are using?

Thanks

imhassan commented 9 years ago

I am using Cordova Version 4.2.0 and android 4.0.

Heshyo commented 9 years ago

@imhassan Do a logcat and check if you don't have an out of memory exception. Also try setting your camera to a lower resolution (eg on an S3 with Android 4.2 and 2GB of RAM, we can resize images if they are 3Mpx, but we quite often get out of memory exception with 6Mpx). Unfortunately it's a recurring issue with Android.

imhassan commented 9 years ago

@Heshyo no out of memory exception it just stopped the app when call to "resize_iamge" function. I even tried with lower resolution image.

Heshyo commented 9 years ago

When the app stops, I usually see the following in logcat:

E/dalvikvm-heap(14422): Out of memory on a 14974336-byte allocation.
I/dalvikvm(14422): "pool-1-thread-1" prio=5 tid=12 RUNNABLE
I/dalvikvm(14422):   | group="main" sCount=0 dsCount=0 obj=0x42f42d50 self=0x6023d050
I/dalvikvm(14422):   | sysTid=14445 nice=0 sched=0/0 cgrp=apps handle=1612960928
I/dalvikvm(14422):   | state=R schedstat=( 465705165 200324788 104 ) utm=42 stm=4 core=2
I/dalvikvm(14422):   at android.graphics.Bitmap.nativeCreate(Native Method)
I/dalvikvm(14422):   at android.graphics.Bitmap.createBitmap(Bitmap.java:726)
I/dalvikvm(14422):   at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
I/dalvikvm(14422):   at android.graphics.Bitmap.createBitmap(Bitmap.java:636)
I/dalvikvm(14422):   at com.synconset.ImageResizePlugin$ResizeImage.getResizedBitmap(ImageResizePlugin.java:252)
I/dalvikvm(14422):   at com.synconset.ImageResizePlugin$ResizeImage.run(ImageResizePlugin.java:211)
I/dalvikvm(14422):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
I/dalvikvm(14422):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
I/dalvikvm(14422):   at java.lang.Thread.run(Thread.java:841)

Note that I would also get a similar exception when using the default camera plugin while specifying a target width/height (meaning that the camera plugin would end up resizing the image).

Maybe you can supply your logcat, to see if there's anything of interest other than an out of memory exception.

clawish commented 9 years ago

You have to specify an absolute directory string in your options that you pass to the function. Along with storeImage and the other parameters. Doing this the resizer does not crash anymore.

RaananW commented 9 years ago

I understand this is now resolved, I am closing the issue, please comment if it still happens.