Objective C从远程url下载图片方法汇总
ObjectiveC从远程url下载图片
-(UIImage*)getImageFromURL:(NSString*)theURL{ UIImage*theImage=NULL; NSString*imageFileName=[BT_stringsgetFileNameFromURL:theURL]; NSData*imageData=[[NSDataalloc]initWithContentsOfURL:[NSURLURLWithString:theURL]]; theImage=[[UIImagealloc]initWithData:imageData]; [BT_fileManagersaveImageToFile:theImagefileName:imageFileName]; returntheImage; }
objectiveC从远程地址获取图片并修改尺寸
NSString*imageURL=[NSStringstringWithFormat:@"http://theimageurl.com/?id=%@",[[resultsEntriesobjectAtIndex:0]objectForKey:@"image_large"]]; NSData*imageData=[[NSDataalloc]initWithContentsOfURL:[NSURLURLWithString:imageURL]]; UIImage*image=[[UIImagealloc]initWithData:imageData]; //resizeimage CGSizenewSize=CGSizeMake(100,100); UIGraphicsBeginImageContext(newSize);//aCGSizethathasthesizeyouwant [imagedrawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; //imageistheoriginalUIImage UIImage*newImage=UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); imageHeight=image.size.height; [imageMainsetImage:newImage]; [imageDatarelease]; [imagerelease];
以上所述就是本文的全部内容了,希望大家能够喜欢。