user2321359
user2321359

Reputation: 101

ios imageResizer NSInvalidArgumentException

I'm having trouble error to resize the image when it is with IMG_DATA gives no error, but when it gives this exception IMG_URI

Error when call resizeImage:

2013-06-26 19:44:30.306 cascalho[13689:15b03] [LOG] Image Resizer Registered under window.imageResizer
2013-06-26 19:44:45.685 cascalho[13689:15b03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSDictionary initWithObjects:forKeys:]: count of objects (0) differs from count of keys (3)'
*** First throw call stack:
(0x171012 0x25c7e7e 0x17c737 0x19d8c2 0x627c 0x7563b 0x74d8c 0x7493d 0x74ad5 0x749f3 0x25db6b0 0x114a765 0xf4f3f 0xf496f 0x117734 0x116f44 0x116e1b 0x33f87e3 0x33f8668 0x3acffc 0x305c 0x2fb5)
libc++abi.dylib: terminate called throwing an exception

Code capturing:

// capture either new or existing photo:
function capture(sourceType) {
    navigator.camera.getPicture(onCaptureSuccess, onCaptureFail, { quality: 40,
                                destinationType: Camera.DestinationType.FILE_URI ,
                                sourceType: sourceType,
                                correctOrientation: true
                                }
                                );
};

var _imageURI =null;
// if photo is captured successfully, then upload to server:
function onCaptureSuccess(imageURI) {
    _imageURI = imageURI;
    var largeImage = document.getElementById('largeImage');
    largeImage.style.display = 'block';
    largeImage.src = imageURI;
};

Code of call resizeImage

window.imageResizer.resizeImage(
            function(data) {
                console.log("ah meu parana: ");

            }, function (error) {
                console.log("Error : \r\n" + error); 
            }, _imageURI,331 , 245, {

                                        imageDataType: ImageResizer.IMAGE_DATA_TYPE_URL,
                                        resizeType:ImageResizer.RESIZE_TYPE_PIXEL ,
                                        format:'jpg'
                                    }
        );

Upvotes: 3

Views: 610

Answers (1)

vscuorzo
vscuorzo

Reputation: 41

I had a similar issue on a current project which I managed to resolve. The problem only occurred on iOS devices, specifically the iPad, and not on my Galaxy S3 or Android emulator. So, after many hours of debugging I noticed that the media capture plugin worked but not the camera plugin and when comparing the two noticed that the camera plugin returned a URI starting with "file://" while the media capture plugin gave a file path like "/var/...". I removed "file://" from the path before passing to resizeImage and everything worked.

In summary, change this:

window.imageResizer.resizeImage(success, failure, imageURI, 300, 0, {});

To this on iOS:

window.imageResizer.resizeImage(success, failure, imageURI.replace('file://',''), 300, 0, {});

This answer is probably too late to help you but hopefully it helps others that run into this problem.

Upvotes: 4

Related Questions