Hey Robert,
Since I'm so liberally linked to I figured I should respond. My
comments are inline.
Simon Mac Donald
http://hi.im/simonmacdonald
To select and image from the Camera/Gallery without loading it into
memory you would want to do this:
var options = {
quality: 100,
destinationType : navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.CAMERA,
encodingType: navigator.camera.EncodingType.JPEG,
}
navigator.camera.getPicture(win, fail, options);
Your "win" method will be called with a URI that points to the image
in question. The image is never loaded into memory and the EXIF
information is never touched. An 8MP camera using JPEG encoding with
100% quality will result in an image of about 2 megabytes. Taking into
account that many 3G service providers cap their upload speeds at 150
kbps you could get a theoretical quickest upload time of about one
minute and 46 seconds.
> So, it would seem that merely getting a URI is not enough, if you wish to
> display the image to the screen, an effective way of resizing is required
> (in addition to any resizing for upload). Using the targetWidth/targetHeight
> is not an option, we must use something native to android, though I fear
> this will lead us in a circle, as a native solution would still require
> loading the image to memory - it almost seems to beg the question, why does
> android allow such large MP count cameras, if it can't handle the processing
> of the images effectively?
If you want to display the image on screen you can use the width and
height parameters of the image tag to specify a size that'll fit on
your screen. That is asking the browser to do a lot of extra work for
you but it can handle it. Alternatively you can use the
targetWidth/targetHeight parameters. I made changes in PG Android that
take advantage of a scaling algorithm that Android provides so we
don't load the entire 8 MP image into memory if we can help it.
For instance if you have a 2000x2000 image and you want a 400x400
image the algorithm will actually load a quarter sized image into
memory at 500x500 and then reduce it down to 400x400. The algorithm
only works in powers of 2 so it will get a half, quarter, eighth,
sixteenth, etc. sized image.
So memory usage is much better now when you are asking for thumbnailed images.
I've looked over this plugin and it suffers from the fact that it
tries to load the entire image into memory at line 193. It could be
improved to use the same algorithm I described to load a smaller
amount of data in memory. However, the way it looks now is that your 8
MP image would probably cause the plugin to throw an out of memory
error as well.
> So, in essence and a nutshell: What is the best way to handle images (esp.
> large images) inside Android / Phonegap (i suspect this is an Android issue,
> not just PhoneGap)? Is there a good process for displaying images on screen
> and also resizing for upload. If the image to upload is a diferent size than
> that shown on screen, a second resize could be required -> second memory
> issue!
Honestly, at this point I'd just go with keeping the large image at
100% quality and letting the browser do the resizing. Please let me
know how that goes.
> After a weekend pondering, Im yet to come to a conclusion on this, though
> plenty of reports and similar queries around without an answer!
>
> Whilst I leave this with the brainstrust, I will test if it is the CSS
> resize causing my memory issue, and see how Raanan Webers plugin plays
>
> talk to you all soon!
> SockThief
Where did my socks go? They're gone but my sneakers are still on.