开发者

how can i display image from url?

I have a string variable tmpImgURLStr which contains URL like www.abc.com/img.png. i want to display that image in my imageView for that i have use some code but it's not working which is given below:

NSLog(@开发者_StackOverflow中文版"Img URL === %@",tmpImgURLStr);

NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",tmpImgURLStr]]]; 

UIImage *myimage = [[UIImage alloc] initWithData:mydata];
[logoImg setImage:myimage];


As far as I can tell from your url - you have pdf, not an image. Usually WebViews are used for displaying this sort of data.

Update

Your NSData initiation is kinda too long. You can actually initiate a URL without supplying formatted string:

NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:tmpImgURLStr]];

Also I've noticed that your URL is without protocol. You may want to try adding http:// or https:// to it and then see what happens. And just in case check if your logoImg is actually wired to the NSImageView in your NIB.


Try this

NSURL *imageurl = [NSURL URLWithString:@"http://www.chakrainteractive.com/mob/ImageUpoad/pic2-2.png"];

NSData *imagedata = [[NSData alloc]initWithContentsOfURL:imageurl];

UIImage *image = [UIImage imageWithData: imagedata];

[logoImg setImage: image];


Try this code instead of yours .. May be it will work..

logoImg=[[IUImageView alloc]initWithFrame:CGRectMake(10,10,300,460)];
NSLog(@"Img URL === %@",tmpImgURLStr);
NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:tmpImgURLStr]]];
UIImage *myimage = [[UIImage alloc] initWithData:mydata];
[logoImg setImage:myimage];

-Happy coding....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜