根据url多线程请求载入网络图片
2012-08-01 16:05
399 查看
-(void) processDownloadImageData:(NSData *) imageData
{
NSString *imagePath = [NSString
stringWithFormat:@"%@/avatar%@.png",document,pathuserID];
if (![imageData writeToFile:imagePath
atomically:YES]) {
NSLog(@"save imageData Error with path:%@",imagePath);
}
//do anything if you want
}//接收到图片后的处理函数
-(void) loadImagebyThread:(NSString *) imageUrlStr
{
NSAutoreleasePool *pool = [[NSAutoreleasePool
alloc] init];
NSURL *imgUrl = [NSURL
URLWithString:imageUrlStr];
NSData *imgData = [NSData
dataWithContentsOfURL:imgUrl];
if (imgData) {
[self performSelectorOnMainThread:@selector(processDownloadImageData:)
withObject:imgData waitUntilDone:NO];
}
[pool release];
}//请求图片的线程函数
在某个需要的地方添加多线程:
NSString *avatar_large_urlStr = [profileDic
objectForKey:@"avatar_large"];
[NSThread
detachNewThreadSelector:@selector(loadImagebyThread:)
toTarget:self withObject:avatar_large_urlStr];
{
NSString *imagePath = [NSString
stringWithFormat:@"%@/avatar%@.png",document,pathuserID];
if (![imageData writeToFile:imagePath
atomically:YES]) {
NSLog(@"save imageData Error with path:%@",imagePath);
}
//do anything if you want
}//接收到图片后的处理函数
-(void) loadImagebyThread:(NSString *) imageUrlStr
{
NSAutoreleasePool *pool = [[NSAutoreleasePool
alloc] init];
NSURL *imgUrl = [NSURL
URLWithString:imageUrlStr];
NSData *imgData = [NSData
dataWithContentsOfURL:imgUrl];
if (imgData) {
[self performSelectorOnMainThread:@selector(processDownloadImageData:)
withObject:imgData waitUntilDone:NO];
}
[pool release];
}//请求图片的线程函数
在某个需要的地方添加多线程:
NSString *avatar_large_urlStr = [profileDic
objectForKey:@"avatar_large"];
[NSThread
detachNewThreadSelector:@selector(loadImagebyThread:)
toTarget:self withObject:avatar_large_urlStr];
相关文章推荐
- Android中如何根据图片url路径来获取网络图片
- HttpURLConnection获取网络数据(实例:网路请求图片)
- 添加引导页 (引导页的图片根据网络请求获取,张数不一定)
- 根据图片的网络URL获取Bitmap
- 根据url下载网络图片
- Handler+HttpURLConnection请求网络图片,字符串
- xcode7 根据URL从网络上下载图片 问题总结
- ISO中根据URL下载图片,请求图片
- 根据URL获取文件,以采集网络图片为例
- Android HttpURLConnection获取网络下载图片POST请求方式
- 【黑马Android】(05)短信/查询和添加/内容观察者使用/子线程网络图片查看器和Handler消息处理器/html查看器/使用HttpURLConnection采用Post方式请求数据/开源项目
- Android 根据网络图片URL转Bitmap对象
- ViewPager广告中的图片请求自网络,监听跳转至点击图片对应Url的webView
- 根据网络url图片路径获取图片字节数组工具类
- 各种网络请求获取URL图片信息
- 图片url中包含中文导致网络请求404
- ios根据URL获得网络图片
- Android中如何根据图片url路径来获取网络图片
- 按钮添加网络请求的图片(多线程)(ios自学笔记)
- Android中如何根据图片url路径来获取网络图片