Objective C: Image download method summary from remote url

Source: Internet
Author: User

Objective C: Image download method summary from remote url

This article will share with you two ways to use Objective C to download images from a remote url. They are all used in personal projects. We recommend them to you in summary. If you need them, you can refer to them.

Objective C downloads images from remote URLs

?

1

2

3

4

5

6

7

8

-(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 gets an image from a remote address and modifies its 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 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];

The above is all the content of this article. I hope you will like it.

Related Article

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.