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 -->
分享到:
相关推荐
uiimage-from-animated-gif, 加载动画gif的UIImage类别 摘要这个项目在 UIImage 上定义了一个类别 animatedGIF 。 类别定义了两种方法。 这里方法使用 data 中GIF的帧创建动画 UIImage: [UIImage ...
UIImage-PDF ,UIImage-PDF 是 UIImage 的分类,实现让 UIImage 支持 PDF 文档的显示...
OC Extension UIImage+FHXImage(图片扩展) 针对UIImage进行封装的工具类。 /** 输入图片颜色返回一张图片 */ + (UIImage *)createImageWithColor:(UIColor *)color; /** 裁切图片的一个点进行延伸 */ - ...
UIImage+Sprite+Animmation
UIImage+ImageEffects 图片模糊处理功能类
WebP-UIImage-源码.rar
UIIMage 改变颜色和遮罩
IOS应用源码——UIImage+Sprite for iOS.rar
UIImage-BlurredFrame, UIImage类别,模糊了UIImage的指定框架 UIImage+BlurredFrame是一个UIImage类别,模糊了UIImage的指定框架#Install使用 cocoapods 安装pod 'UIImage+BlurredFrame'#Usage
stretchableImageWithLeftCapWidth resizableImageWithCapInsets
方便查找图片,直接能够显示图片大小与内容,很方便,支持Xcode6
颜色创建图像工具 UIImage-ImageWithColor ,UIImage-ImageWithColor 是一款使用颜色创建图像的工具
Uiimage+category,uiimage+watermark,uiimageview+category实现对于图片添加水印的功能
iOS图片压缩---UIImage+Wechat【可以对图片进行很好的压缩,而且像素不会减少很多,很优秀的图片压缩框架】
一个简单轻量的照片浏览器,可以通过传入url或UIImage创建,支持转场动画,自定义指示器样式位置,提供手势回调。
UIImage 图片处理:截图,缩放,设定大小,存储
给 UIView 或 UIImage 高性能添加圆角,生成渐变色图片等
/** * 给图片加水印图片 * * @param image 水印图片 ...- (UIImage*)imageWaterMarkWithImage:(UIImage *)image imageRect:(CGRect)imgRect alpha:(CGFloat)alpha; /** * 同上 * * @param image 同上 *
NULL 博文链接:https://o0o0o0o.iteye.com/blog/937475