如何使用 CPImage 从 URL 下载图像?
我有一个 CPImage:
-(void)setAvatarImageForMessage:(STMessage)aSTMsg{
var image = [[CPImage alloc] initWithContentsOfFile:aSTMsg.avatar_url];
[image setDelegate:self];
if([image loadStatus] == CPImageLoadStatusCompleted)
CPLog.debug("avatar image loaded");
else
CPLog.debug("avatar image FAILED!!!");
}
但不确定这是否是从 URL 下载图像的正确方法?
I have a CPImage:
-(void)setAvatarImageForMessage:(STMessage)aSTMsg{
var image = [[CPImage alloc] initWithContentsOfFile:aSTMsg.avatar_url];
[image setDelegate:self];
if([image loadStatus] == CPImageLoadStatusCompleted)
CPLog.debug("avatar image loaded");
else
CPLog.debug("avatar image FAILED!!!");
}
But am not sure if this is the correct way to download an image from a URL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是创建图像的方式,但您不能指望它立即加载。图像(就像网络上的其他所有内容一样)异步加载。如果您需要知道图像何时加载,可以注册通知。
That's how you create an image, but you can't expect it to load immediately. Images (like just about everything else on the web) load asynchronously. If you need to know when the image has loaded, you can register for a notification.