2012-04-23 13 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

+0

私はそうは思わない。いくつかのサンプルプロジェクトからコードを入手しました。私はそれを行う方法がわかりません。ありがとう – Clarence

答えて

2

[ここにリンクの説明を入力します] [1]ラインに従うことによって、この行(NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 1.0);)を変更します。..

NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 0.0); 

または

NSData *smallImageData = UIImagePNGRepresentation(smallImage); 

希望、これは役立ちますあなた.. ..

0

(^。^)「こんにちは申し訳ありませんが、誰かがように私の改訂を修正した場合、私の英語が良くないために、私はこれをいただければ幸いです」

は、あなたが1つのUIImageViewと彼の財産contentModeと試みたことがありますか?このような :

UIImageView *imagen = [[UIImageView alloc] initWithFrame:CGRectMake(X, Y, W, H)]; 
[imagen setContentMode:UIViewContentModeScaleAspectFit]; 
関連する問題