RaananW / PhoneGap-Image-Resizer

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

Instant crash on android :/ #26

Closed roblav96 closed 8 years ago

roblav96 commented 8 years ago

I get an instant crash of my app when trying to use this plugin.

Logcat:

E/AndroidRuntime(24259): FATAL EXCEPTION: pool-3-thread-2
E/AndroidRuntime(24259): Process: com.tech401.testApp, PID: 24259
E/AndroidRuntime(24259): java.lang.IllegalArgumentException: URI is not hierarchical: data:image/jpeg;base64,/9j/4AAQSkZJRg.....................
D/Error   (24259): ERR: exClass=java.lang.IllegalArgumentException
D/Error   (24259): ERR: exMsg=URI is not hierarchical: data:image/jpeg;base64,/9j/4AAQSkZJRgABAQA.....................
D/Error   (24259): ERR: file=File.java
D/Error   (24259): ERR: class=java.io.File
D/Error   (24259): ERR: method=checkURI line=222
D/Error   (24259): ERR: stack=java.lang.IllegalArgumentException: URI is not hierarchical: data:image/jpeg;base64,/9j/4AAQSkZJRgAB.....................
D/Error   (24259): ERR: TOTAL BYTES WRITTEN: 675824
W/ActivityManager(  756):   Force finishing activity 1 com.tech401.testApp/.MainActivity

How's she lookin?

Here's my code:

var canvasurl = canvas.toDataURL( "image/jpeg" )
window.imageResizer.resizeImage( function ( data ) {
    var imgg = "data:image/jpeg;base64," + data.imageData;
    console.log( 'imgg >', imgg )
}, function ( error ) {
    console.log( "Error : \r\n" + error );
}, canvasurl, 0.5, 0.5, {
    resizeType: ImageResizer.FORMAT_JPG,
    format: 'jpg'
} )
RaananW commented 8 years ago

Hi,

you are missing the imageDataType. So it is trying to read a URL. You also have resizeType a but wrong (should be either pixel or factor) here is a corrected version that should work.

var canvasurl = canvas.toDataURL( "image/jpeg" )
window.imageResizer.resizeImage( function ( data ) {
    var imgg = "data:image/jpeg;base64," + data.imageData;
    console.log( 'imgg >', imgg )
}, function ( error ) {
    console.log( "Error : \r\n" + error );
}, canvasurl, 0.5, 0.5, {
    resizeType: ImageResizer.RESIZE_TYPE_FACTOR,
    imageDataType: ImageResizer.IMAGE_DATA_TYPE_BASE64,
    format: ImageResizer.FORMAT_JPG
} )
roblav96 commented 8 years ago

Ah. That would make sense. I was trying to follow the example on the readme.md but it didn't provide enough details. Thank you!!

RaananW commented 8 years ago

Yeah, my fault :-) Just updated the readme.

roblav96 commented 8 years ago

Sweet! Sounds good. I'm gonna try it out now. Thank you!

roblav96 commented 8 years ago

Still not working :/

var canvasurl = canvas.toDataURL( "image/jpeg" )
console.log( 'canvasurl >', canvasurl )
window.imageResizer.resizeImage( function ( data ) {
    var imgg = "data:image/jpeg;base64," + data.imageData
    console.log( 'imgg >', imgg )
}, function ( error ) {
    console.error( "window.imageResizer.resizeImage > " + error )
}, canvasurl, 0.5, 0.5, {
    resizeType: ImageResizer.RESIZE_TYPE_FACTOR,
    imageDataType: ImageResizer.IMAGE_DATA_TYPE_BASE64,
    format: ImageResizer.FORMAT_JPG,
    quality: 100
} )

var canvasurl =

data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMD…B1GK9M0fU472Ffm/OvmMbgpYWemqPeyvNPbNUK3xdH3NWijIPSiuLc94KayBuo+lOopNCsf//Z

the console.log is truncating the url. If you need the whole thing I can get it.

roblav96 commented 8 years ago

I think I need to change it to base64.

EDIT Still nothing.

RaananW commented 8 years ago

Issue reopened :-) What error are you getting? still the same exception?

roblav96 commented 8 years ago

I'm in class right now, but I just got it working after clean installing my app. Strange. lol Thank you!!!