I am using
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
to take t开发者_StackOverflow中文版he image.
Then useCGImageRef 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.
精彩评论