*smile* Ah, another nutter working on the weekend. I *like* that about you.
Okay, I've gotten to the bottom of my troubles.
There were four problems befuddling my simple mind:
1) If you're expecting a base64 encoded string, you need to specify it in the options (watch out for wrap here)
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 100, targetWidth: 200, targetHeight: 200, encodingType:encodingType.PNG, saveToPhotoAlbum:false,destinationType:destinationType.DATA_URL });
}
2) If you're expecting a fileURI, explicitly state that in the options (again, 'ware wrap):
// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100, allowEdit: true, targetWidth: 400, targetHeight: 100,encodingType:encodingType.PNG, saveToPhotoAlbum:false,destinationType:destinationType.FILE_URI });
}
3) Finally, *always* explicitly state the size of the image you want back. If you give -1 and -1 allowing the camera to default to whatever size, and the user chooses a big size (2048x1536 on my Galaxy 2 10), then the app eventually gets too big, crashes silently, and then all bets are off. Note in both of the camera calls above I'm stating the targetWidth/Height desired.
4) The docs say that you must use both Width/Height together, but that aspect ratio is retained.
That's not my experience...the picture seemed to be scaled to the specified size, disregarding the aspect ratio altogether.
When I gave a height but not a width is that I got back a picture 1xheight in size. Artsy, but not desired behaviour.
If you state 0 for either width/height you get crashes or the new image being ignored.
Looking in the code for getScaledBitmap, I confess I'm not clear on how it works:
1) get size of current image
2) calculate widthHeight respecting aspect ratios
3) calculate the sampling rate
4) sample the original bitmap (doesn't this change the aspect ratio before it is scaled?)
5) resize the new sample to the stated size. (but if the aspect ratio is borked already what are we getting?)
So, the docs are misleading. It does work, but you must sacrifice goats, and dance around fires late at night for it to work "properly".
Could have been (partially) prevented with better docs...can you change the API page at:
-Ken