gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:59:11 25 4
gpt4 key购买 nike

我在下面有以下代码。首先,在表格详细 View 中,我捕获或加载图像(图像的大小约为屏幕的 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];
}

最佳答案

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

NSData *smallImageData = UIImageJPEGRepresentation(smallImage, 0.0);

NSData *smallImageData = UIImagePNGRepresentation(smallImage);

希望这对你有帮助..

关于iphone - 使用 CoreData 保存图像后分辨率发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10274666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com