This article to share 2 of the use of objective C from the remote URL to download pictures of the method, are used in individual projects, summarized under the recommendation to everyone, the need for small partners can refer to.
Objective c download pictures from remote URL
?
1 2 3 4 5 6 7 8 |
-(UIImage *) Getimagefromurl: (NSString *) theURL {uiimage = 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 Gets the picture from the remote address and modifies the size
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16-17 |
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 for you want [image Drawinrect:cgrectmake (0,0,newsize.wid Th,newsize.height)]; Image is the original uiimage uiimage* newimage = Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); ImageHeight = Image.size.height; [Imagemain Setimage:newimage]; [ImageData release]; [Image release]; |
The above mentioned is the entire content of this article, I hope you can enjoy.