从iOS库导入时显着的图像质量损失

时间:2012-04-14 15:31:38

标签: ios xcode

我正在使用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库:

enter image description here

我的UIImageView:

enter image description here

2 个答案:

答案 0 :(得分:0)

也许你应该使用

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

获取原始图片。

答案 1 :(得分:0)

我在使用通用应用时发现了类似的问题。使用allowEditing = YES从iPod touch上的相册中拾取图像工作正常,质量没有降低,但在iPad上UIImagePickerControllerEditedImage只有320像素宽,导致质量下降,我认为因为用于编辑的popover只是320像素宽!

经过多次搜索,我偶然发现了this code使用字典中用户剪裁的裁剪设置再次剪裁原始图像,但我无法感受到那里的感受。在iPad上处理此问题的更好方法