Cross-platform SDK and HTML5 tools for mobile app development
X
 
19 posts / 0 new
Last post
lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:
Image compression

Hi,

Sorry if this has been addressed before, I tried to search but could not find anything.

I need to upload images to a web application. The image is selected using the image picker. I can get the raw image data with maGetImageSize(), maGetImageData(), encode it with base64 and pass it on, however, the data is huge, especially for a mobile application.

Is there any way I could compress the data in PNG or JPEG? Or, better yet, is there a way I can access the original, compressed file data when using the image picker?

Edit: The app runs on Android and iOS devices.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Hey good question. There isn't an in-built method for compressing images, but the save picture methods call down to the OS to do that. Are you trying to send a picture the user has just taken? If you, so can save the image to their device, and then read the automatically compressed image as binary data!

maCaptureWriteImage(mLatestPictureTakenHandle, "\sdcard\MyPhoto.jpg", 20);

Will save the image to the device, using the (I'm guessing here) the default compression method of that device, which I guess will be JPEG.  You can use the FileSystem API to read back that encoded image, B64 and post.

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

Thanks for your reply, Sam. The idea was good, unfortunately it's giving me a MA_CAPTURE_RES_INVALID_HANDLE error.

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

Have you replaced 'mLatestPictureTakenHandle' with the actual handle to the image you've taken?

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

Ummm, yes, otherwise it wouldn't have compiled... :D

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

It's not a picture I've just taken, but one returned from maImagePickerOpen().

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

I've been digging around a bit and here's what I found:

On iOS, the stock image picker is shown, the maImagePickerOpen() is just a wrapper to handle the event etc. On Android, the picker is implemented from scratch. It's clumsy, doesn't look particularly nice and, worst of all, it force closes every time after some scrolling (most probably due to some bug in the caching code or just simply it runs out of memory).

Why couldn't the Android Gallery be used for this, just like on iOS? Seems like that would have been the "native" way of implementing this.

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:

From 3.0.1 (end of the month) the Android Gallery will be used (implementation done, waits QA).

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

That's awesome, Ovidiu. Thanks for the info! Is it available in the nightlies?

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:

The implementation has already been integrated in the 3.0.1 branch and it should be in the next nightly build.

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

It must be this commit... It was made on the 13th, just like the nightly build. Perhaps it made it into the build. I'll check too. Thanks again.

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:

Yep, that's it, but I've checked already and it is not there yet :( So you'll have to wait: today or tomorrow there should be another nightly build.

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

Just checked, it's not in yet. Sigh. And now the app force-closes on start. And I've lost the Eclipse plugins. That'll teach me to install nightlies over stable... :)

Ovidiu
ovidiu's picture
Offline
Mobile Sorcerer
Joined: 27 Jan 2011
Posts:

You read my thoughts ;)

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

How hard would it be to add an extra parameter to the EVENT_TYPE_IMAGE_PICKER that would be the url of the selected image? This way I could just open the file from the FS and deal with it properly, no need to re-compress.

The (both the old and new) implementation on Android reads the image from the file, but he iOS implementation seems to get an image object and deals with that directly. It is quite possible (not an iOS expert by far...) that the image does not even always come from a file - in that case the point would be of course moot.

The image data associated with a MoSync handle seems to always be in ARGB format (correct me if I'm wrong) - thereby making it impossible to get the original, compressed data back from it. Maybe the best would be after all to add some image compression routines on the platforms that support it (should be all of them)... Thoughts?

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

Shameless bump. :)

lacapaca
lacapaca's picture
Offline
Joined: 18 Feb 2012
Posts:

Created issue 2069 for this.

carolinenew
carolinenew's picture
Offline
Joined: 10 Apr 2013
Posts:

from what i see, image programme an easily convert or compress data.but whether  you can access the original file data,just need to try. i am not so clear.

dannyrough
dannyrough's picture
Offline
Joined: 26 Apr 2013
Posts:

you can employ an imaging sdk which can do such kind of compression. there are a lot of such sdks on the internet , just try some and i think you can get what you want.