Store image using UIImage from NSURL

Using UIImage, I know that we can store an image from a URL. But now I am stuck at some point when it does not work for me. I am trying to capture an image from a url as below:

NSString *filename = @"12121212" 
UIImage *logoImage = [UIImage imageNamed:[NSString stringWithFormat:@"http://www.example.com/devlopment.cfm?method=%@",fileName]];
NSURL *url = [NSURL URLWithString: logoImage];

I am sure that I am getting an image, but I can’t upload it.

Am I going the right way?

Sagos

+3
source share
2 answers

You will need UIImage +imageWithData:and :NSData +dataWithContentsOfURL:

NSString *fileName = @"12121212";
NSString *filePath = [NSString stringWithFormat:@"http://www.example.com/devlopment.cfm?method=%@",fileName];
UIImage *im = [UIImage imageWithData: [NSData dataWithContentsOfURL:[NSURL URLWithString:filePath]]];
+14
source

In your example, you have things in some reverse order. Installation UIImage *logoImageshould be the last part. In addition, turning a URL into an image is a two-step process.

First you need to get the data:

NSString *filename = @"12121212"; 
NSURL *tempURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.example.com/devlopment.cfm?method=%@",fileName]];
NSData *tempData = [NSData dataWithContentsOfUrl:tempURL];

:

UIImage *logoImage = [UIImage imageWithData:tempData];

, , , .

+1

Source: https://habr.com/ru/post/1791598/