BlueDolphin
BlueDolphin

Reputation: 9765

Anyone could exlain width/height returned from iphone camera taken image on iPhone 4?

I am using

- (void)imagePickerController:(UIImagePickerController *)picker 
  didFinishPickingImage:(UIImage *)image
      editingInfo:(NSDictionary *)editingInfo

to take the image.
Then use

  CGImageRef imgRef = image.CGImage;

 CGFloat width = CGImageGetWidth(imgRef);
 CGFloat height = CGImageGetHeight(imgRef);

For some reason, the width always 640, and height always 480. no matter whether it is portrait or landscape.

I really confused on that, I thought in portraint, it should be width 320 and height is 480, while in landscape mode, width should be 480 and height should be 320.

What am I missing? How do I get correct width and height of the image. Thanks.

Upvotes: 0

Views: 1042

Answers (2)

Deniz Mert Edincik
Deniz Mert Edincik

Reputation: 4361

You should implement something like this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    CGImageRef ref = image.CGImage;
    int width = CGImageGetWidth(ref);
    int height = CGImageGetHeight(ref);
    NSLog(@"image size = %d x %d", width, height);

    UIImage *orig = [editingInfo objectForKey:UIImagePickerControllerOriginalImage];
    ref = orig.CGImage;
    width = CGImageGetWidth(ref);
    height = CGImageGetHeight(ref);
    NSLog(@"orig image size = %d x %d", width, height);

    CGRect origRect;
    [[editingInfo objectForKey:UIImagePickerControllerCropRect] getValue:&origRect];

    NSLog(@"Crop rect = %f %f %f %f", origRect.origin.x, origRect.origin.y, origRect.size.width, origRect.size.height);
}

For more discussion pease see: http://discussions.apple.com/thread.jspa?messageID=7841245&tstart=0

Upvotes: 2

greg
greg

Reputation: 4953

imagePickerController:didFinishPickingImage:editingInfo: is depreciated as of iOS 3.0.

Try using imagePickerController:didFinishPickingMediaWithInfo: and see if it makes a difference.

Upvotes: 1

Related Questions