Reduce UIImage size to a manageable size (reduce bytes)

I want to reduce the number of bytes of an image captured by the device, since i believe the _imageScaledToSize does not reduce the number of bytes of the picture (or does it?) - i want to store a thumbnail of the image in a local dictionary object and can't afford to put full size images in the dictionary. Any idea?

Answers


If you wish to simply compress your UIImage, you can use

NSData *dataForPNGFile = UIImagePNGRepresentation(yourImage);

to generate an NSData version of your image encoded as a PNG (easily inserted into an NSDictionary or written to disk), or you can use

NSData *dataForPNGFile = UIImageJPEGRepresentation(yourImage, 0.9f);

to do the same, only in a JPEG format. The second parameter is the image quality of the JPEG. Both of these should produce images that are smaller, memory-wise, than your UIImage.

Resizing a UIImage to create a smaller thumbnail (pixels-wise) using published methods is a little trickier. _imageScaledToSize is from the private API, and I'd highly recommend you not use it. For a means that works within the documented methods, see this post.


Need Your Help

millis() function overflow in Tinygps library

c++ c gps arduino

I am making a GPS device to run for about a year without restarting. I am using TinyGPS+ library. I noticed that there are millis() functions in the library. So they can overflow. Is there a way to...

Can not deserialize instance of Task out of START_ARRAY token

java json hibernate extjs

I m having problem while deserialization of more than one tasks(data) from a JSON file we are sending from our EXTJS store. While updating single task its working correct. but when we update more t...