UIImagePickerControllerEditedImage问题

时间:2012-03-28 09:44:47

标签: iphone objective-c ios xcode ios5

我需要在导入到应用程序之前编辑我的图像但是在编辑图像后降低了一些质量如何避免这种情况?

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [self dismissModalViewControllerAnimated:YES];
    imgEdited.image = [info objectForKey:UIImagePickerControllerEditedImage];


}

4 个答案:

答案 0 :(得分:4)

您可以使用UIImagePickerControllerOriginalImage提供的值手动裁剪UIImagePickerControllerCropRect

未经测试的快速和肮脏的例子:

static UIImage *my_croppedImage(UIImage *image, CGRect cropRect)
{
    UIGraphicsBeginImageContext(cropRect.size);
    [image drawAtPoint:CGPointMake(-cropRect.origin.x, -cropRect.origin.y)];
    UIImage *cropped = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return cropped;
}

- (void) imagePickerController:(UIImagePickerController *)picker
 didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // …

    UIImage *originalImage = info[UIImagePickerControllerOriginalImage];
    CGRect cropRect = [info[UIImagePickerControllerCropRect] CGRectValue];
    UIImage *croppedImage = my_croppedImage(originalImage, cropRect);

    // …
}    

答案 1 :(得分:1)

- (void)imagePickerController:(UIImagePickerController *)picker 
                      didFinishPickingMediaWithInfo:(NSDictionary *)info {

  [picker dismissModalViewControllerAnimated:YES];
  [picker release];

          // Edited image works great (if you allowed editing)
  myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
          // AND the original image works great
  myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
          // AND do whatever you want with it, (NSDictionary *)info is fine now
  UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];
}

您可以编辑图像。试试这个可能适用于你的应用程序。谢谢!

答案 2 :(得分:0)

降低质量与您上面提供的代码无关。图像的质量取决于您在编辑过程中对图像的处理。您是否放大并裁剪图像?

答案 3 :(得分:0)

确定。这听起来很糟糕。但是图像质量是否真的很低,还是仅仅显示为低质量?

您可能希望将此图像导出到PC并检查其实际质量较低,而不仅仅是将图像显示为低质量。