- 浏览: 303707 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
yahier:
没帮助。。。。。。
利用JS获取经纬度,定位html地图 -
mountainol:
[img][img][img][img][url][flash ...
iPhone面试题解答,真机调试 -
qww_friend:
很不错的一个案例,试了下,没有报错,就是我想要的
Poi读取Excel2007 -
zcw_java:
peng051410 写道啥时候能更新呢?求解! 好久没弄过了 ...
Spring Security-session过期跳出<iframe> -
peng051410:
啥时候能更新呢?求解!
Spring Security-session过期跳出<iframe>
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *fileURL = [NSString stringWithFormat:@"http://%@/image/%@/show.jpg?n=%d", 1,1]; NSData *dateImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]; dispatch_sync(dispatch_get_main_queue(), ^{ m_imgViewVideo.image = [UIImage imageWithData:dateImg]; if (![ABServices bIsPreview]) { m_nPreviewCount = 0; } }); [pool drain];
dispatch_sync:提交块对象给指定的调剂队列,同步履行。
dispatch_async:提交块对象给指定的调剂队列,异步履行。
dispatch_async() 调用以后立即返回,dispatch_sync() 调用以后等到block执行完以后才返回,dispatch_sync()会阻塞当前线程。
//访问图片时响应404的没获取到数据时,判断code,0为ok
NSString *strURL = [NSString stringWithFormat:kUrlReadCameraAlarmInfo,[ABServices currentUserName],strSubClass];
NSError *error = nil;
NSData *dataImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL] options:NSDataReadingMappedIfSafe error:&error];
if ([error code] == 0)
{
//截取图片压缩
UIImage *imgCompress = [self image:[UIImage imageWithData:dataImg] centerInSize:CGSizeMake(140, 140)];
NSData *dataCompress = UIImageJPEGRepresentation(imgCompress, 1.0);
[self saveImage:dataCompress nIndex:indexPath.row picName:strSubClass];
}
以下是在tableview中全部代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"cate_cell"; CateTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[CateTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } //cell默认图片 UIImageView *imgDefault = [[UIImageView alloc] init]; imgDefault.image = [self image:[UIImage imageNamed:@"alarm_icon.png"] centerInSize:CGSizeMake(140, 140)]; //获取每条报警记录 NSDictionary *cate = [m_mutArrAlarmPicList objectAtIndex:indexPath.row]; NSString *strImgPath = [NSString stringWithFormat:@"%@_0.jpg",[cate objectForKey:@"alarmPic"]]; //搜索缓存 UIImage *image = [self searchCacheImg:strImgPath nCellIndexPath:indexPath.row]; if(image != nil) { imgDefault.image = image; } else { dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSString *strURL = [NSString stringWithFormat:kUrlReadCameraAlarmInfo,[ABServices currentUserName],strImgPath]; NSError *error = nil; NSData *dataImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL] options:NSDataReadingMappedIfSafe error:&error]; if ([error code] == 0) { //截取图片压缩 UIImage *imgCompress = [self image:[UIImage imageWithData:dataImg] centerInSize:CGSizeMake(140, 140)]; NSData *dataCompress = UIImageJPEGRepresentation(imgCompress, 1.0); [self saveImage:dataCompress nIndex:indexPath.row picName:strImgPath]; dispatch_sync(dispatch_get_main_queue(), ^{ imgDefault.image = [UIImage imageWithData:dataCompress]; NSArray *arrRows = [NSArray arrayWithObjects:indexPath, nil]; [_tableView reloadRowsAtIndexPaths:arrRows withRowAnimation:UITableViewRowAnimationNone]; }); } }); } cell.logo.image = imgDefault.image; [imgDefault release]; cell.title.text = [self stringFormatDate:[cate objectForKey:@"alarmPic"]]; cell.subTtile.text = [NSString stringWithFormat:@"%@",[cate objectForKey:@"alarmSensor"]]; return cell; }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SubCateViewController *subVc = [[[SubCateViewController alloc] initWithNibName:NSStringFromClass([SubCateViewController class]) bundle:nil] autorelease]; NSDictionary *cate = [m_mutArrAlarmPicList objectAtIndex:indexPath.row]; subVc.m_nIndexPathRow = indexPath.row; //保存选中cell索引 m_nSelectedCellIndex = indexPath.row; NSMutableArray *mutArrPics = [[NSMutableArray alloc] init]; for (int i=0; i < 10; i++) { NSString *strSubClass = [NSString stringWithFormat:@"%@_%d.jpg",[cate objectForKey:@"alarmPic"],i]; [mutArrPics addObject:strSubClass]; dispatch_async(dispatch_get_global_queue(0, 0), ^{ //搜索图片是否存在 UIImage *image = [self searchCacheImg:strSubClass nCellIndexPath:indexPath.row]; if(image == nil) { NSString *strURL = [NSString stringWithFormat:kUrlReadCameraAlarmInfo,[ABServices currentUserName],strSubClass]; NSError *error = nil; NSData *dataImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL] options:NSDataReadingMappedIfSafe error:&error]; if ([error code] == 0) { //截取图片压缩 UIImage *imgCompress = [self image:[UIImage imageWithData:dataImg] centerInSize:CGSizeMake(140, 140)]; NSData *dataCompress = UIImageJPEGRepresentation(imgCompress, 1.0); [self saveImage:dataCompress nIndex:indexPath.row picName:strSubClass]; } } }); } subVc.subCates = mutArrPics; [mutArrPics release]; // self.currentCate = cate; subVc.cateVC = self; self.tableView.scrollEnabled = NO; UIFolderTableView *folderTableView = (UIFolderTableView *)tableView; [folderTableView openFolderAtIndexPath:indexPath WithContentView:subVc.view openBlock:^(UIView *subClassView, CFTimeInterval duration, CAMediaTimingFunction *timingFunction){ // opening actions } closeBlock:^(UIView *subClassView, CFTimeInterval duration, CAMediaTimingFunction *timingFunction){ // closing actions } completionBlock:^{ // completed actions self.tableView.scrollEnabled = YES; }]; }
发表评论
-
ios序列化对象存储本地
2013-09-10 14:14 1676#import <Foundation/Founda ... -
Tableview详解
2013-08-22 15:47 1255一,为tableview中cell,修改其样式 [tabl ... -
使用MKNetworkKit函数Demo
2013-08-16 13:41 4176一、引入MKNetworkKit 1,添加MKNetwork ... -
ios国际化
2013-08-15 15:22 809前些天升级到Xcode4.5,现在正在用Xcode4.5+IO ... -
SDWebImage Demo手册
2013-08-13 12:58 1086分享源码,有问题回复 SDWebImage 异步加载 缓存图 ... -
ios文件读写
2013-08-12 15:44 953//写入缓存文件,缓存目录下 NSArray * ... -
ios使用预编译命令解决问题
2013-08-12 13:44 1906对于MacOS设备不同,做出相应响应 #if TARGET ... -
tableview设置上下滚动高度,启用删除
2013-08-06 17:14 1684可在viewDidAppear中实现加入 [tablvew s ... -
UILable手册
2013-08-02 13:25 8201,自动算出长度,宽度 CGSize notRecomment ... -
NSMutableArray排序
2013-07-26 15:44 1192NSMutableArray *array = [NS ... -
NSDate和NSString的转换
2013-07-15 14:43 772用于uidate,picker。。 +(NSDate ... -
c++结构体在ios端解析
2013-07-11 09:20 1081定义宏和结构体 #define ENTRYCOUNT 10 ... -
NSDate-常用操作及控制
2013-07-05 10:42 6992对于NSDate常用操作整理,如有不足请补充 1,获取当前时 ... -
NotifiCationCenter控制使用
2013-07-02 11:31 1069NSNotificationCenter 第一种,这个只是传 ... -
UIImage压缩和缩放
2013-07-01 14:31 2913节省大量内存,重绘缩略图; #define K_conten ... -
转载ios开发资源汇总
2013-06-28 15:02 1790如何用Facebook graphic api上传视频: h ... -
ios将模拟器与真机.a文件合并
2013-06-24 16:54 47971,command+b build一下工程 2,Debug- ... -
UITableViewCell自定义
2013-06-18 16:22 2209添加到选中cell中,每一个cell闪烁1秒 [tableVi ... -
PickerView准备捕获时间,循环滚动demo
2013-06-18 15:09 4372最重要的下面几行代码 - (void) clickRigh ... -
UI圆角以及阴影等效果利用layer属性
2013-06-17 10:42 6355制作圆角button等 //必须导入的空间 #impor ...
相关推荐
NSData NSDate NSDictionary NSException NSFileManager NSObject NSSet NSString NSTimer NSURL UIKit UIBezierPath UIButton UIColor UIDevice UIImage UIImageView UILable UINavigationController UIResponder...
(UIImage *)animatedImageWithAnimatedGIFData:(NSData *)theData; url 图实现: (UIImage *)animatedImageWithAnimatedGIFURL:(NSURL *)theURL; github: https://github.com/His-writing/gitDemo
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrlString]]; UIImage *image = [UIImage imageWithData:imageData]; UIImageView *imageView = [[UIImageView alloc] initWithImage...
- (UIImage *)downloadImageFromUrl:(NSURL *)url { // 使用GCD异步下载图片 UIImage *image = nil; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData *data = ...
UIImage *image = [UIImage imageWithData:imageData]; // 使用图片 } ``` 关于标签中的“canvas”,在某些情况下,图片可能存储在HTML5的Canvas元素内。这时,需要通过JavaScript的`toDataURL()`方法将Canvas...
HZ扩展类别UIColor , UIButton , UIAlertView , UIView , NSDate , NSFileManager , NSDictionary , NSString , UIImage , NSData , NSAttributedString , NSURL , NSArray 。 一些常见的宏和助手类。 ...
IOS开发中加载大量网络图片如何优化 1、概述 在IOS下通过URL读一张网络图片并不像其他编程语言那样可以直接把图片路径放... NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]; result =
UIImage *image = [UIImage imageNamed:@"example.jpg"]; NSData *imageData = UIImageJPEGRepresentation(image, 0.8); // 质量为0.8的JPEG格式数据 NSString *urlString = @"http://yourserver.com/upload"; ...
在Objective-C中,我们会用到`Foundation`框架中的`NSURLSession`和`NSData`类,以及`UIKit`框架中的`UIImage`类。确保在你的`.m`文件顶部有以下导入: ```objc #import #import ``` 接下来,我们将创建一个方法...
NSURL *url = [NSURL URLWithString:@"http://example.com/image.jpg"]; ``` 接下来,使用`NSURLRequest`来包装这个URL,以便`NSURLConnection`可以发送请求: ```objc NSURLRequest *request = [NSURLRequest ...
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:banarModel.avatar.url]]; UIImage *image = [UIImage imageWithData:data]; }); ``` 使用`dataWithContentsOfURL:`方法从指定URL下载图片...
Haneke是用Swift 4编写... Haneke为UIImage , NSData , JSON , String或可以作为数据读取或写入的任何其他类型提供内存和LRU磁盘缓存。 特别是Haneke擅长处理图像。 它包括一个具有自动调整大小的零配置图像缓存。
数据: NSData 图片: UIImage或NSImage XML: NSXMLParser 可可豆 使用将安装到您的项目中。 pod 'HandsomeURLSession' ##用法 获取一个NSURLSession let session = NSURLSession. sharedSession () 为要...
- (NSData *)compressImage:(UIImage *)image withQuality:(CGFloat)quality { if (quality || quality > 1.0) { quality = 0.8; // 设置默认压缩质量 } NSData *imageData = UIImageJPEGRepresentation(image...
UIImage *image = [UIImage imageNamed:@"image"]; NSData *imageData = UIImageJPEGRepresentation(image, 0.9); AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:...
NSData *imageData = UIImageJPEGRepresentation(image, 1.0); // 质量设为1.0,即最高质量 ``` 2. **构造请求参数**: 除了图片数据,可能还需要其他参数,如用户ID、图片标题等。这些参数可以以键值对的形式...
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:theURL]]; theImage = [[UIImage alloc] initWithData:imageData]; [BT_fileManager saveImageToFile:theImage fileName:...
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]; // 下载完成后,回到主线程更新UI dispatch_async(dispatch_get_main_queue(), ^{ imageView.image = image; }); } ``` 在...
- (void)lk_requestImageSizeFromURL:(NSURL *)url completion:(void(^)(CGSize size, NSError *error))completion { NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:...