Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone ($4.99)

dotnetIQ ($4.99)

Your First iPhone App ($1.99)

iPocket Tools 9 in 1 ($0.99)

Catch-Me (Free)

Alien Strike ($0.99)

Historic Olympic Medal-Table ($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-28-2009, 05:33 PM   #1 (permalink)
Lost in a sea of code
 
BostonMerlin's Avatar
 
Join Date: Apr 2008
Location: Boston
Posts: 385
Default Compressing images for synchronization

Hi gang.. I need some advice.

My app lets users take a picture or choose a picture from the image library and save it to their device. Behind the scenes I'm taking that picture and saving out to my server via a http post. Once posted anyone else running this app will automatically get a copy of that image the next time they sync.

I've been playing around with different ways to compress these images before posting to my server. Keep in mind, images might be huge if taken with the camera or very small if the user copied a small image from the web to their photo library. Image size might be anywhere from a few kb to six or more megabytes. The heigh and width of an image would vary greatly as well.

My primary requirement is to make sure the images size is no more than a few hundred kb max and the quality of the image is still legible after compression .

I'm playing around with UIImageJPEGRepresentation changing the compression level based on the length of the file but I'm getting results which are all over the board.. some images after compression have been compressed so much they're blurry to images that are too big to be transfered.

Example code:
Code:
NSData *imageData = UIImageJPEGRepresentation(theImage,1.0);
len = [imageData length];
if (len >100000) imageData =  UIImageJPEGRepresentation(theImage,0.5);
if (len > 90000) imageData =  UIImageJPEGRepresentation(theImage,0.3);

I don't think grabbing the length is the way to do this.. but i'm not sure what else to try. If you have any ideas i'm all ears!

Thanks
John
__________________
----------------------------------------------------------------------
I love being a dad, flying airplanes and writing code.
----------------------------------------------------------------------
Follow me on Twitter: @BostonMerlin
Feed your brain on Twitter: @iPhoneDev101
----------------------------------------------------------------------
iPhone Apps:

Last edited by BostonMerlin; 01-28-2009 at 05:37 PM.
BostonMerlin is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


» Advertisements
» Stats
Members: 21,483
Threads: 35,768
Posts: 156,679
Top Poster: smasher (2,448)
Welcome to our newest member, guelinator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:02 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0