From time to time I need to know the width and height of the images. I am using the following code:
UIImage *imageU = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"myImage.png"]];
CGFloat imageW = CGImageGetWidth(imageU.CGImage);
CGFloat imageH = CGImageGetHeight(imageU.CGImage);
My question is if there is any other way to know the width and height of the image, in pixels, without having to load the image onto a variable, possibly consuming memory. Can dimensions be read directly from the file without downloading the entire image?
This should work for PNG and JPEG.
thank.
source
share