A question came up over the weekend as to download an image off the internet and add it to a UIImage object on the iPhone. The answer is to create an NSData object that grabs the contents of the URL and then initialize the image with that data, as such:
id path = @"http://merrimusings.mu.nu/archives/images/groundhog2.jpg"; NSURL *url = [NSURL URLWithString:path]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *img = [[UIImage alloc] initWithData:data cache:NO];<!-- ISI_LISTEN_STOP -->
本文介绍了如何通过Objective-C从互联网下载一张图片,并将其转换为UIImage对象的过程。具体步骤包括:使用NSURL获取图片URL,利用NSData下载图片内容,最后初始化UIImage对象。
6594

被折叠的 条评论
为什么被折叠?



