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.
Related
- (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.
I want to dispay an online image in imageview and save it to database
following code display only a particular image. I can also save that image to database.
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://tvaraj.files.wordpress.com/2012/03/sachin-tendulkar-when-young.jpg&w=231&h=2500&ei=SiKqT9-fKILprQfIudWCAQ&zoom=1"]]];
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
img.image=[UIImage imageWithData:data1];
NSLog(#"image=%#",img.image);
imageToUse1= img.image;
[image release];
//i want to add this code. this is for
WebView *Wview=[[WebView alloc]init];
[self.navigationController pushViewController:Wview animated:YES];
My requirement is if I click any image that should display in the imageview.
How is it possible?
UIImage* myImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString: #"http://example.com/image.jpg"]]];
And if you want to use it on an image view just do the following:
// Let's assume the picture is an instantiated UIImageView
[picture setImage: myImage];
[myImage release];
Save image to Database
NSData *data1 = UIImagePNGRepresentation(myImage, 1.0); // save this nsdata to ur database.
I have no idea why this isn't working.
NSData *data = [NSData dataWithContentsOfURL:place.iconData];
UIImage *image = [UIImage imageWithData:data];
[imageView setImage:image];
imageView is an IBOutlet hooked up through IB. place.iconData is http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png. For some reason, though, it won't load. Any help is much appreciated.
Try this:
NSURL *url = [NSURL URLWithString: #"http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
[imageView setImage:image];
//or imageView.Image=image;
Is your data being freed before it got assigned?
Maybe try manually allocating memory for the NSData:
NSData *data = [[NSData alloc] initWithContentsOfURL:place.iconData];
UIImage *image = [[UIImage alloc] initWithData:data];
[imageView setImage:image];
[data release];
[image release];
You need to use NSURL. Follow this url http://iosdevelopertips.com/cocoa/download-and-create-an-image-from-a-url.html
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.
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....