繁体   English   中英

从照片库获取照片不起作用

[英]Get a photo from photo library not working

我是XCode的新手,我想从照片库中选择一张照片。

- (void) ChoosePhoto_from_Album
{
    UIImagePickerController *imgage_picker = [[UIImagePickerController alloc] init];
    imgage_picker.delegate = self;
    imgage_picker.allowsEditing = YES;
    imgage_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:imgage_picker animated:YES completion:NULL];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
      UIImage *  image = [info objectForKey:UIImagePickerControllerOriginalImage];

      NSLog(@"ImagePicker image size = (%.0f x %.0f)", image.size.width , image.size.height);
      // process image...
}

我选择的照片是5MP(2592x1936)。 但是,它返回的大小是960x716。 我想念什么?

谢谢 !

我找到了此链接。 通过使用以下包含的代码,可以使用Three20框架。

这是您的解决方案

UIImagePickerController确实为您提供了完整的基于相机的图像。 您需要从imagePickerController:didFinishPickingImage:editingInfo方法的editingInfo参数获取它。

- (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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM