下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
//从网络下载图片-(UIImage *) getimageFromURL:(Nsstring *)fileURL { NSLog(@"执行图片下载函数"); UIImage * result; NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]]; result = [UIImage imageWithData:data]; return result;}//将所下载的图片保存到本地-(voID) saveImage:(UIImage *)image withfilename:(Nsstring *)imagename ofType:(Nsstring *)extension inDirectory:(Nsstring *)directoryPath { if ([[extension lowercaseString] isEqualToString:@"png"]) { [UIImagePNGRepresentation(image) writetofile:[directoryPath stringByAppendingPathComponent:[Nsstring stringWithFormat:@"%@.%@",imagename,@"png"]] options:NSAtomicWrite error:nil]; } else if ([[extension lowercaseString] isEqualToString:@"jpg"] || [[extension lowercaseString] isEqualToString:@"jpeg"]) { [UIImageJPEGRepresentation(image,1.0) writetofile:[directoryPath stringByAppendingPathComponent:[Nsstring stringWithFormat:@"%@.%@",@"jpg"]] options:NSAtomicWrite error:nil]; } else { //ALog(@"Image Save Failed\nExtension: (%@) is not recognized,use (PNG/JPG)",extension); NSLog(@"文件后缀不认识"); }}//读取本地保存的图片-(UIImage *) loadImage:(Nsstring *)filename ofType:(Nsstring *)extension inDirectory:(Nsstring *)directoryPath { UIImage * result = [UIImage imageWithContentsOffile:[Nsstring stringWithFormat:@"%@/%@.%@",directoryPath,filename,extension]]; return result;}//从网络下载图片,保存,并用 UIImageVIEw 从保存中显示Nsstring * documentsDirectoryPath = [NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0]; NSLog(@"保存路径:%@",documentsDirectoryPath); //Get Image From URL UIImage * imageFromURL = [self getimageFromURL:@"http://file.duteba.com/phone/2009/04/5/ftGxL8kcul.jpg"]; //Save Image to Directory [self saveImage:imageFromURL withfilename:@"MyImage" ofType:@"jpg" inDirectory:documentsDirectoryPath]; //Load Image From Directory UIImage * imageFromWeb = [self loadImage:@"MyImage" ofType:@"jpg" inDirectory:documentsDirectoryPath]; [img setimage:imageFromWeb]; //取得目录下所有文件名 NSArray *file = [[[NSfileManager alloc] init] subpathsAtPath:documentsDirectoryPath]; //NSLog(@"%d",[file count]); NSLog(@"%@",file);//该片段来自于http://outofmemory.cn
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的objective-c 从网络下载图片,保存,并用 UIImageView 从保存中显示全部内容,希望文章能够帮你解决objective-c 从网络下载图片,保存,并用 UIImageView 从保存中显示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)