本文给大家分享了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实现轮询的三种方式 2023-02-17
 - 作为iOS开发,这道面试题你能答出来,说明你基础很OK! 2023-09-14
 - SurfaceView播放视频发送弹幕并实现滚动歌词 2023-01-02
 - Flutter实现底部和顶部导航栏 2022-08-31
 - Android MaterialButton使用实例详解(告别shape、selector) 2023-06-16
 - 最好用的ios数据恢复软件:PhoneRescue for Mac 2023-09-14
 - Android实现监听音量的变化 2023-03-30
 - iOS 对当前webView进行截屏的方法 2023-03-01
 - Android studio实现动态背景页面 2023-05-23
 - 详解flutter engine 那些没被释放的东西 2022-12-04
 
						
						
						
						
						
				
				
				
				