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: