我正在使用iPad照片庫(相機膠捲)導入一些圖像,並將它們放入使用alloc方法創建的UIImageView中。但是當顯示圖像時會有很大的圖像質量損失。例如,在圖書館中,有一張圖像的河流非常銳利,逐個像素,但是當我輸入它時,它會丟失至少一半的像素。這是導入圖像的代碼:從iOS庫導入時導致顯着的圖像質量損失
- (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:
你意思是代替UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage]; ?? – Alessandro 2012-04-18 18:51:29
是的,作品非常好。即使我的這種方式也可以:UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage]; – Alessandro 2012-04-18 18:57:20
...但沒有編輯選項,我想保留編輯版本! – Alessandro 2012-04-18 18:57:49