Objective C Download Picture method rollup from remote URL

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.