广

IOS开发

  • IOS开发
  • android开发
  • PHP编程
  • JavaScript
  • ASP.NET
  • ASP编程
  • JSP编程
  • Java编程
  • 易语言
  • Ruby编程
  • Perl编程
  • AJAX
  • 正则表达式
  • C语言
  • 编程开发

    Objective C从远程url下载图片方法汇总

    2018-04-03 22:30:41 次阅读 稿源:互联网
    广告

    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 imageCGSize 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 UIImageUIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();     imageHeight = image.size.height;[imageMain setImage:newImage];[imageData release];[image release];

    以上所述就是本文的全部内容了,希望大家能够喜欢。

    一起学吧部分文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与一起学吧进行文章共享合作。

    广告
    广告
    广告