Objective-c determine image resolution

For some reason I could not figure it out.

UIImage *image = //initialize with some image, etc. 

Is there a way to get image resolution?

+4
source share
2 answers

Do you mean width / height?

 CGFloat width = image.size.width CGFloat height = image.size.height 
+6
source

To find image sizes, you can use the size property on UIImage . DPI (resolution / scale) can be found using the scale attribute. Here is the link from the Apple Documentation :

Scale image ratio. (Only for reading)

 @property (nonatomic,readonly) CGFloat scale 

Discussion

If you load an image from a file whose name includes the @ 2x modifier, the scale is set to 2.0. If the file name does not contain a modifier, but is in PNG or JPEG format and has an associated DPI value, the corresponding scaling factor is calculated and reflected in this property. You can also specify an explicit scale factor when initializing an image from a Core Graphics image. All other images are assumed to have a scale factor of 1.0.

If you multiply the logical size of the image (stored in the size property) by the value in this property, you get the image dimensions in pixels.

For ordinary images, the scale will be 1.0. For JPG / PNG images, the scale may vary. Also, if your image name has "@ 2x" before the extension, UIImage assumes that its scale is 2.0.

+2
source

All Articles