RaananW / PhoneGap-Image-Resizer

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

Problem when image is stored on device (Android) #28

Open jonasrod opened 8 years ago

jonasrod commented 8 years ago

When I select an image from gallery in android, cause app crash, or when I use cordova camera plugin and set savetophotoalbum, it's cause the same problem.

Heshyo commented 8 years ago

Can you do a logcat to check the kind of exception you get? OutOfMemoryException is quite common when handling large images on Android. Maybe you can try importing a very small image.

RaananW commented 8 years ago

I assume you are using the base 64 variant? as Heshyo said, this could happen due to lack of memory. What device are you using? what is the image size?

jonasrod commented 8 years ago

@Heshyo I don't get any exception in javascript console. I don't think this problem is OutOfMemoryException, because the same code works when set savetophotoalbum to false. The problem seems to occurs just when the image is stored in the gallery. @RaananW My device is LG G3, and the problem occur with both small image (e.g. 25k) or large image.

RaananW commented 8 years ago

Can you see the Java/Android log? there must be an exception thrown if the app crashes. Can you also paste the js code you are using?

jonasrod commented 8 years ago

I didn't used the base64 variant. I changed to base64 and it works now. But, follow my original code:

var options = { quality: 30, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY, allowEdit: false, encodingType: Camera.EncodingType.JPEG, saveToPhotoAlbum: true, correctOrientation: true }

$cordovaCamera.getPicture(options).then(function(imageUrl) { console.log(imageUrl); var imageUri = imageUrl; var resizeOptions = { imageDataType: ImageResizer.IMAGE_DATA_TYPE_URL, resizeType: ImageResizer.RESIZE_TYPE_MIN_PIXEL, storeImage: false, photoAlbum: false, format: ImageResizer.FORMAT_JPG };

window.imageResizer.resizeImage(function(data) { FileService.storeImage("data:image/jpeg;base64," + data.imageData); resolve(); }, function (error) { console.log("Error : \r\n" + error); }, imageUri, 200, 0, resizeOptions);

The code above don't work.