本文给大家分享了2则使用Objective C从远程url下载图片的方法,都是个人项目中使用的,汇总下推荐给大家,有需要的小伙伴可以参考下。
Objective C从远程url下载图片
- (UIImage *) getImageFromURL: (NSString *)theURL {
UIImage *theImage = NULL;
NSString *imageFileName = [BT_strings getFileNameFromURL:theURL];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:theURL]];
theImage = [[UIImage alloc] initWithData:imageData];
[BT_fileManager saveImageToFile:theImage fileName:imageFileName];
return theImage;
}
objective C从远程地址获取图片并修改尺寸
NSString* imageURL = [NSString stringWithFormat: @"http://theimageurl.com/?id=%@", [[resultsEntries objectAtIndex:0] objectForKey: @"image_large"]];
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:imageURL]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
// resize image
CGSize newSize = CGSizeMake(100, 100);
UIGraphicsBeginImageContext( newSize );// a CGSize that has the size you want
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
//image is the original UIImage
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imageHeight = image.size.height;
[imageMain setImage:newImage];
[imageData release];
[image release];
以上所述就是本文的全部内容了,希望大家能够喜欢。
织梦狗教程
本文标题为:Objective C从远程url下载图片方法汇总


基础教程推荐
猜你喜欢
- Android中的webview监听每次URL变化实例 2023-01-23
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Android多返回栈技术 2023-04-15
- android studio按钮监听的5种方法实例详解 2023-01-12
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Flutter手势密码的实现示例(附demo) 2023-04-11
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04