9

我正在使用 iPad 照片库(相机胶卷)导入一些图像,并将它们放在我使用 alloc 方法创建的 UIImageView 中。但是当显示图像时,图像质量损失很大。例如,在库中,有一张河流的图像非常清晰,逐个像素,但是当我导入它时,它至少丢失了一半的像素。这是导入图像的代码:

- (IBAction) useCameraRoll: (id)sender
{
    @autoreleasepool {

if ([self.popoverController isPopoverVisible]) {
    [self.popoverController dismissPopoverAnimated:YES];

} else{

    }{
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        @autoreleasepool {

        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];

        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage,
                                  nil];

        imagePicker.allowsEditing = YES;

        self.popoverController = [[UIPopoverController alloc]
                                  initWithContentViewController:imagePicker];
        }
        popoverController.delegate = self;

        [self.popoverController 
         presentPopoverFromBarButtonItem:sender
         permittedArrowDirections:UIPopoverArrowDirectionUp
         animated:YES];


        newMedia = NO;


    }}
}
}

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self.popoverController dismissPopoverAnimated:true];
@autoreleasepool {

NSString *mediaType = [info
                       objectForKey:UIImagePickerControllerMediaType];

if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
    UIImage *image = [info
                      objectForKey:UIImagePickerControllerEditedImage];

    image1.image = image;
    if (newMedia)
        UIImageWriteToSavedPhotosAlbum(image,
                                       self,  
                                           @selector(image:finishedSavingWithError:contextInfo:),
                                       nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
    // Code here to support video if enabled
}}
}

-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
 contextInfo:(void *)contextInfo
{
if (error) {
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Save failed"
                          message: @"Failed to save image"\
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];
}
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{

}

以及质量差异(图像放大),但即使在小范围内您也可以清楚地看到差异:

iOS 库:

在此处输入图像描述

我的 UIImageView:

在此处输入图像描述

4

2 回答 2

0

也许你应该使用

UIImage *img = [info valueForKey:@"UIImagePickerControllerOriginalImage"];

获取原始图像。

于 2012-04-18T14:31:12.323 回答
0

在开发通用应用程序时,我注意到了类似的问题。在 iPod touch 上使用 allowEditing=YES 从相册中挑选图像效果很好,没有质量损失,但在 iPad 上 UIImagePickerControllerEditedImage 仅 320 像素宽,导致质量损失,我认为因为用于编辑的弹出框仅320像素宽!

经过大量搜索后,我遇到了这段代码,可以使用字典中的用户裁剪设置再次裁剪原始图像,但我不禁觉得在 iPad 上必须有更好的方法来处理这个问题

于 2013-04-24T14:55:36.183 回答