2012-04-23 38 views
0

我在下面有下面的代碼。首先,在表細節視圖中,我捕獲或加載圖像(圖像的大小約爲屏幕的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

回答

2

[此處輸入鏈接的描述] [1]更改此行(NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 1.0);)通過以下線..

NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 0.0); 

NSData *smallImageData = UIImagePNGRepresentation(smallImage); 

希望,這將有助於你..

0

(^。^)「嗨,對不起我的英語不是很好,如果有人喜歡糾正我的新版本我將不勝感激這個」

你有一個UIImageView的嘗試和他的財產contentMode? 這樣的:

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