objective-C從遠程地址獲取圖片并修改尺寸

y35w 9年前發布 | 4K 次閱讀 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];</pre>

 本文由用戶 y35w 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!