使用CoreData保存图像后分辨率发生变化

问题描述:

我在下面有下面的代码。首先,在表细节视图中,我捕获或加载图像(图像的大小约为屏幕的1/4),然后保存图像后将显示在UITableView上。一切似乎进展顺利。但是,当我按下UITable并尝试再次加载详细信息页面时。图像的分辨率降低。我猜是和TableView的一样大小。请问我能做些什么来解决这个问题?使用CoreData保存图像后分辨率发生变化

谢谢。

-(void) ViewDidLoad{ 
     if ([currentPicture smallPicture]) 
       [imageField setImage:[UIImage imageWithData:[currentPicture smallPicture]]]; 
    } 

- (IBAction)editSaveButtonPressed:(id)sender 
      { 

      // If we are adding a new picture (because we didnt pass one from the table) then create an entry 
       if (!currentPicture) 
        self.currentPicture = (Pictures *)[NSEntityDescription insertNewObjectForEntityForName:@"Pictures" inManagedObjectContext:self.managedObjectContext]; 

     if (imageField.image) 
     // Resize and save a smaller version for the table 
        float resize = 74.0; 
        float actualWidth = imageField.image.size.width; 
        float actualHeight = imageField.image.size.height; 
        float divBy, newWidth, newHeight; 
        if (actualWidth > actualHeight) { 
         divBy = (actualWidth/resize); 
         newWidth = resize; 
         newHeight = (actualHeight/divBy); 
        } else { 
         divBy = (actualHeight/resize); 
         newWidth = (actualWidth/divBy); 
         newHeight = resize; 
        } 
        CGRect rect = CGRectMake(0.0, 0.0, newWidth, newHeight); 
        UIGraphicsBeginImageContext(rect.size); 
        [imageField.image drawInRect:rect]; 
        UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext(); 
        UIGraphicsEndImageContext(); 

        // Save the small image version 
        NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 1.0); 
        [self.currentPicture setSmallPicture:smallImageData]; 
       } 
+0

你有没有尝试记录的图像的大小,然后再保存它,然后加载它? – EmilioPelaez 2012-04-23 04:31:40

+0

我不认为我有。我从一些示例项目中获得了代码。我不知道该怎么做。谢谢 – Clarence 2012-04-23 04:41:31

[此处输入链接的描述] [1]更改此行(NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 1.0);)通过以下线..

NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 0.0); 

NSData *smallImageData = UIImagePNGRepresentation(smallImage); 

希望,这将有助于你..

(^。^)“嗨,对不起我的英语不是很好,如果有人喜欢纠正我的新版本我将不胜感激这个”

你有一个UIImageView的尝试和他的财产contentMode? 这样的:

UIImageView *imagen = [[UIImageView alloc] initWithFrame:CGRectMake(X, Y, W, H)]; 
[imagen setContentMode:UIViewContentModeScaleAspectFit];