我在下面有以下代码。首先,在表格详细视图中,我捕获或加载图像(图像大小约为屏幕的 1/4),然后保存后图像将显示在 UITableView 中。到目前为止,一切似乎都很顺利。但是,当我按下 UITable 并尝试再次加载详细信息页面时。图像的分辨率降低。我猜它的大小与 TableView 中的大小相同。我可以知道我能做些什么来解决这个问题吗?
谢谢。
-(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];
}