Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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, 04:33 PM   #1 (permalink)
Lost in a sea of code
 
BostonMerlin's Avatar
 
Join Date: Apr 2008
Location: Boston
Posts: 388
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 04: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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Online Users: 281
19 members and 262 guests
cakesy, camtadao, crooksy88, Erle, Eskema, Falcon80, ghanalupo, jojo453, josh, kiancheong, mixer555, odysseus31173, SalvoMaltese, shay_somech, SkodaBuddy, StefanL, Stitch, Susan03, thadre
Most users ever online was 779, 05-11-2009 at 09:55 AM.
» Stats
Members: 24,280
Threads: 39,072
Posts: 171,337
Top Poster: smasher (2,575)
Welcome to our newest member, Susan03
Powered by vBadvanced CMPS v3.1.0

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