以下のコードがあります。まず、テーブル詳細ビューでは、画像をキャプチャまたは読み込み(画像のサイズは画面の約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];
}
保存する前とロードした後で画像のサイズを記録しようとしましたか? – EmilioPelaez
私はそうは思わない。いくつかのサンプルプロジェクトからコードを入手しました。私はそれを行う方法がわかりません。ありがとう – Clarence