[Objective-C] objective C从远程地址获取图片并修改尺寸 →→→→→进入此内容的聊天室

来自 , 2019-03-07, 写在 Objective-C, 查看 145 次.
URL http://www.code666.cn/view/f8e6ba1d
  1. NSString* imageURL = [NSString stringWithFormat: @"http://theimageurl.com/?id=%@", [[resultsEntries objectAtIndex:0] objectForKey: @"image_large"]];
  2. NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:imageURL]];      
  3. UIImage* image = [[UIImage alloc] initWithData:imageData];
  4.  
  5. // resize image
  6. CGSize newSize = CGSizeMake(100, 100);
  7. UIGraphicsBeginImageContext( newSize );// a CGSize that has the size you want
  8. [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
  9.  
  10. //image is the original UIImage
  11. UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
  12. UIGraphicsEndImageContext();           
  13.  
  14. imageHeight = image.size.height;
  15. [imageMain setImage:newImage];
  16. [imageData release];
  17. [image release];
  18. //objectc/3903

回复 "objective C从远程地址获取图片并修改尺寸"

这儿你可以回复上面这条便签

captcha