how to load url image in image view in iphone - iphone

- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://www.scri8e.com/effects/FL0WERZ/PNG/ir09.png"];
data = [[NSData alloc]initWithContentsOfURL:url ];
UIImage *img = [[UIImage alloc]initWithData:data ];
imageview.image=img;
}
above is my code but it does not load the image in image view

Try this library it will help you download images and display in the imageview.

The same code working for me fine !!!!!!
Please check the Internet Connection.
Please check the NSData *data size
Please check the UIImageView Size
Please check it hided by some other controls
Please check it added properly to your View
Please check its Content View
#property(nonatomic,retain) IBOutlet UIImageView *imageview;
NSURL *url = [NSURL URLWithString:#"http://www.scri8e.com/effects/FL0WERZ/PNG/ir09.png"];
NSData *data = [[NSData alloc]initWithContentsOfURL:url ];
UIImage *img = [[UIImage alloc]initWithData:data ];
self.imageview.image=img;

If you are taken imageview directly in xib, than just check connection in connection inspector.

NSString *mainimg=[NSString stringWithFormat:#"%#",[[xmlDataDictionary valueForKeyPath:#"eg.main.img1"]objectAtIndex:indexPath.row]];
NSURL *url = [NSURL URLWithString:mainimg];
NSData *image = [[NSData alloc] initWithContentsOfURL:url];
cell.img.image=[UIImage imageWithData:image];
Try this for parsed url..
So simple..

- (void)viewDidLoad
{
[super viewDidLoad];
NSString *url_Img1 = #"http://www.scri8e.com/effects/FL0WERZ/PNG";
NSString *url_Img2 = #"ir09.png";
NSString *url_Img_FULL = [url_Img1 stringByAppendingPathComponent:url_Img2];
NSLog(#"Show url_Img_FULL: %#",url_Img_FULL);
_view_Image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL]]];
}

use EgoImageView instead of ImageView.

Related

How to display multiple image in thumbnail and Not able to play audio in iphone

I am new to iOS programming. I'm fetching images and audios file from server. After that, using below code, I am trying to display all images as a thumbnail. Can any one tell me how can I display all images as a thumbnail. Also audio is not playing.
-(IBAction)fullsizeimage:(id)sender
{
////////////// Image ////////////////////////////
NSURL *url = [NSURL URLWithString:#"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/thumbnail_small/326.png"];
NSData *data = [NSData dataWithContentsOfURL: url];
UIImage *image = [UIImage imageWithData:data];
imagee = [[UIImageView alloc] initWithImage: image];
[self.view addSubview:imagee];
NSURL *url1 = [NSURL URLWithString:#"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/thumbnail_small/327.png"];
NSData *data1 = [NSData dataWithContentsOfURL: url1];
UIImage *image1 = [UIImage imageWithData:data1];
imagee1 = [[UIImageView alloc] initWithImage: image1];
[self.view addSubview:imagee1];
NSURL *urll = [NSURL URLWithString:#"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/thumbnail_small/325.png"];
NSData *dataa = [NSData dataWithContentsOfURL: urll];
UIImage *imageee = [UIImage imageWithData:dataa];
imagee2 = [[UIImageView alloc] initWithImage: imageee];
[self.view addSubview:imagee2];
/////////////// Audio ///////////////////////
NSURL *audiourl = [NSURL URLWithString:#"http://182.73.152.59:82/php/tauky_services/codeigniter-restserver-master/uploads/45/Audio/312.mp3"];
NSData *audioData = [NSData dataWithContentsOfURL:audiourl];
NSError *error;
//AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioData error:&error];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:audioData error:&error];
audioPlayer.numberOfLoops = -1;
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
}
Thanks
Aslam
Consider assigning a different frame to each image before you add them to the superview. It's possible that your code assigns the same frame for each image.
Use NSLog(#"%#", [self.view subviews]); to know if the image views are present and loaded.
Set different UIImageView (with your required thumbnail frame) on your main view and then add these image's on it.
You can cosider using a GridView from the moriarty library, either as a large grid in a UIScrollView, or on a more efficient row-by-row basis in a UITableView.
You could use TTPhotoViewController from the
Three20 project, which works as iOS built in camera roll to view images.

Cannot Fetch UIImage from URL

i am trying to fetch an image from URL, but i am not able to do it.
can any one let me know what went wrong
find the code below for your reference.
NSString *ImageURL = #"http://images.pcmac.org/SiSFiles/Schools/TN/JacksonMadisonCounty/RoseHillMiddle/Uploads/Locations/{B690E93E-F7C9-48AF-B72A-BFF944FA6D4A}_104_9169.JPG";
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
img.image = [UIImage imageWithData:imageData];
where img is a UIImageView
i just create DEMO of Your ImageURL you just Need to put Code Bellow:-
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *ImageURL = #"http://images.pcmac.org/SiSFiles/Schools/TN/JacksonMadisonCounty/RoseHillMiddle/Uploads/Locations/{B690E93E-F7C9-48AF-B72A-BFF944FA6D4A}_104_9169.JPG";
ImageURL =[ImageURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(#"img url ==%#",ImageURL);
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:ImageURL]];
UIImage *MYimage = [UIImage imageWithData:data];
NSLog(#"==%#",MYimage);
[imgview setImage:MYimage];
}
Download the Demo i just created of your image URL:-
http://www.sendspace.com/file/m966ae
Thank you :)
Try this.......
NSString *ImageURL = #"http://images.pcmac.org/SiSFiles/Schools/TN/JacksonMadisonCounty/RoseHillMiddle/Uploads/Locations/{B690E93E-F7C9-48AF-B72A-BFF944FA6D4A}_104_9169.JPG";
NSData *data = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:ImageURL]];
UIImage *IMG = [UIImage imageWithData:data];
img.image = IMG;
This is because you have "{" and "}" in your imageURL so you are not able to get your image, so just replace this braces.
-(NSString*)replace:(NSString*)string
{
NSString *str = [[string stringByReplacingOccurrencesOfString:#"{" withString:#"%7B"] stringByReplacingOccurrencesOfString:#"}" withString:#"%7D"];
return str;
}
You have to create your url object in the following way :
NSURL *url = [NSURL URLWithString:[ImageURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
then use that url to fetch data. Hope it will work for you.
there are multiple ways to get Image from Url. you can use anyone. but the fastest one that i have tried is
-(UIImage*)getImageFromURLwithUrl:(NSString*)imgURLStr
{
NSMutableURLRequest *requestWithBodyParams = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:imgURLStr]];
NSData *imageData = [NSURLConnection sendSynchronousRequest:requestWithBodyParams returningResponse:nil error:nil];
UIImage *image = [UIImage imageWithData:imageData];
return image;
}

NSURL code to display an image from a sqlite table

Ii'm using this NSURL code to display an image. what I want to do is to insert a url from my database table in place of the static url shown in the code below:
Does anyone know how I should proceed?
NSURL *url = [NSURL URLWithString:#"http://www.nyapplecountry.com/images/photosvarieties/redrome04.jpg"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
[self.view addSubview:[[UIImageView alloc] initWithImage:image]];
[self.containerView addSubview:self.mainView];
I was thinking of something like:
NSString *urlAddress = [NSString stringWithFormat:#"%#", place.url];
where place.url is coming from my db table. I'm missing something though, not sure what.
thanks for any help
Is place.url a NSString object and the full URL to the image? Then it would be as simple as
NSURL *url = [NSURL URLWithString:place.url];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
You can't do it that way. You have to read image from data base and initialize UIImage with that data.

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(#"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....

Show image from url in uiimageview

I try to show a image in my iphone app but it doesn't show. I connect in IB and I check to show a local image, it workd good. I also check the url from image and it is ok. I use the next code:
NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
imageView.image = image;
and
//Video.h
NSString *urlThumbnail;
and this is my code on the view.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"URLTHUMBNAIL: %#", aVideo.urlThumbnail);
NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
imageView.image = image;
}
NSLog getts on console
URLTHUMBNAIL: http://147.83.74.180/thumbnails/56.jpg
The connections on IB are ok, cause I can display a local image using next code on the same IBAction
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:#"barret" ofType:#"png"]];
It can be very helpful to NSLog() yourself some notes about what's really in your variables. If you really do have everything hooked up right in IB, it could be that aVideo.urlThumbnail isn't getting set. I'd like to see that value in the console right before creating your NSURL with it.
First off, since NSData dataWithContentsOfURL: accesses the network, you should consider doing that in the background. Otherwise, your UI may become unresponsive.
You should consider adding some additional logging to check the value of imageData and image. Also, you can call NSData dataWithContentsOfURL:options:error: to see if that's the source of the failure.