Objective C从远程url下载图片方法汇总
程序员文章站
2022-06-09 19:46:14
objective c从远程url下载图片
- (uiimage *) getimagefromurl: (nsstring *)theurl {
ui...
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];
以上所述就是本文的全部内容了,希望大家能够喜欢。