Image Compression
Hi. I've got an application (runs on iPhone simulator) and runs OK on my iPhone 3GS (4.0.2 ios).
It captures an image from the camera/phone, some meta data and posts this to a webservice. No error, just times out. I'm guessing it's an issue with the image size.
Any suggestions on how to compress the image before sending?
Thanks.
Jennifer
6 Answers
-
Accepted Answer
I've spent several hours looking into this. Since I don't know objective C (thus why I'm using Titanium in the first place), I found a way to hack the class to statically change the compression level. Here's what I did to get this to work (for iPhone):
Navigate to /Library/Application Support/Titanium/mobilesdk/osx/1.4.x/iphone/Classes
Open the files TiBlob.m and PLSqlitePreparedStatement.m files and change the code "UIImageJPEGRepresentation(value, 1.0)" to "UIImageJPEGRepresentation(value, x.x)" where x.x = your compression level between 0 and 1.
Rebuild your iphone build and myImage.toImage() should now output to that compression level.
If anyone has a better solution, I'm all ears.
-
jennifer,
post your code ( using correct formatting syntax ) or a link to the code on pastie.org and i'll check it out to give you some advise.rocksteady,
danno~ -
Do you have any good suggestion on image compression? I want to kind a fine toolkit whose way of processing is simple and fast to help me with that. Thanks in advance.
Best regards,
Arron -
It must be very convenient to use iphone devices to compress image without any external procedures to install image compressing software on PC.
-
It must be very convenient to use iphone devices to compress image without any external procedures to install image compressing software on PC.
-
Much easier to do this
Titanium.Media.showCamera({
success:function(event)
{
var image = event.media;//CREATE IMAGEVIEW WITH event.media - USE HEIGHT & WIDTH AS AUTO TO GET IMAGE DIMENSIONS
var image1 = Ti.UI.createImageView({
image: image,
height: 'auto',
width: 'auto'
});//RESIZE IMAGE - HERE IS DIVIDING THE IMAGE DIMENSIONS BY 4
var image = image.imageAsResized((image1.width/4), (image1.height/4));
//…………
xhr.send({media:image});},