Search code examples
iosobjective-cimageimage-manipulation

Image size on Objective-C


How to get Image size in Objective-C.

I loaded one image using imagePicker, I want know the size of that image. (w*h)

is it possible?

Thanks & regards...


Solution

  • You implement the UIImagePickerControllerDelegate Protocol and in particular the imagePickerController:didFinishPickingMediaWithInfo: method. The last parameter in that method is a dictionary that includes an UImage references by the UIImagePickerControllerOriginalImage key. Get this UIImage* and get it's size property.

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
        UIImage *image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];
        //access width and height like this
        image.size.width;
        image.size.height;
    }