Saturday, October 15, 2011

iPhone | UIImage

I was reading a blog article "How to use optimized Image in iPhone Development?",

That article suggests, it is best to use “imageWithContentsOfFile” over [UImage imageNamed:@"YOUR_IMAGE_NAME"]; because image name will not flush image out of memory even if it is set to nil.

Correct! it will not flush, But its good to keep that image in cache, Most of the time, application user moves to-and-fro in app ,
So its not a good idea to get it always from main bundle and get it converted everytime!

Sharing the good part of UIImage:

As per apple developer reference guide for UIImage imageNamed method:

+ (UIImage *)imageNamed:(NSString *)name

The name of the file. If this is the first time the image is being loaded, the method looks for an image with the specified name in the application’s main bundle.
If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

Return Value
The image object for the specified file, or nil if the method could not find the specified image.

On a device running iOS 4 or later, the behavior is identical if the device’s screen has a scale of 1.0. If the screen has a scale of 2.0, this method first searches for an image file with the same filename with an @2x suffix appended to it. For example, if the file’s name is button, it first searches for button@2x. If it finds a 2x, it loads that image and sets the scale property of the returned UIImage object to 2.0. Otherwise, it loads the unmodified filename and sets the scale property to 1.0.
Special Considerations
On iOS 4 and later, if the file is in PNG format, it is not necessary to specify the .PNG filename extension. Prior to iOS 4, you must specify the filename extension.

No comments:

Post a Comment