gpt4 book ai didi

iphone - 是否可以使用 connectionDidFinishLoading 中的 UIGraphicsBeginImageContext?

转载 作者:行者123 更新时间:2023-11-29 11:20:31 24 4
gpt4 key购买 nike

我在执行下面的代码时遇到了这些错误:

[Switching to process 74682 thread 0x2003]
[Switching to process 74682 thread 0x207]
[Switching to process 74682 thread 0x720f]

--

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
UIImage = [[UIImage alloc] initWithData:self.resp_data;
CGSize itemSize = CGSizeMake(150);
UIGraphicsBeginImageContext(itemSize);
CGRect image_rect = CGRectMake(0.0,0.0,itemSize.width,itemSize.height);
[image drawInRect:image_rect];
self.image_view.image = UIGraphicsGetImageFromCurrentImageContext(); // image_view ivar is connected to a UIImageView in the View associated to this controller
self.resp_data = nil;
self.imageConnection = nil;
[image release];

}

知道可能是什么问题以及如何解决吗? (当然,预期的图像没有出现)

感谢您的帮助,

史蒂芬

最佳答案

测试代码:100% 有效

 #define kAppIconHeight 48

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Set appIcon and clear temporary data/image
UIImage *image = [[UIImage alloc] initWithData:self.resp_data];

if (image.size.width != kAppIconHeight && image.size.height != kAppIconHeight)
{
CGSize itemSize = CGSizeMake(kAppIconHeight, kAppIconHeight);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[image drawInRect:imageRect];
self.image_view.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else
{
self.image_view.image = image;
}

self.resp_data = nil;
[image release];

// Release the connection now that it's finished
//self.imageConnection = nil;

// call our delegate and tell it that our icon is ready for display
// [delegate appImageDidLoad:self.indexPathInTableView];
}

关于iphone - 是否可以使用 connectionDidFinishLoading 中的 UIGraphicsBeginImageContext?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7454635/

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