【问题标题】:Get a photo from photo library not working从照片库中获取照片不起作用
【发布时间】:2014-08-07 22:16:19
【问题描述】:

我是 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。 我错过了什么?

谢谢!

【问题讨论】:

  • 设备(iPhone、iPad 等)上的图片在与 iTunes 同步时重新缩放。可能是你的情况......

标签: ios photo


【解决方案1】:

我找到了这个链接。您可以使用以下包含的代码来使用 Three20 框架。

这是你的solution

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多