开发者

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

开发者 https://www.devze.com 2023-01-21 07:27 出处:网络
I am using - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image

I am using

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

to take t开发者_StackOverflow中文版he 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.


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


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消