I have imageView i want to load image from url but it is not loading i am using following code
pdfView.hidden=NO;
webView.hidden=NO;
pictureImageView.hidden=NO;
pdfView.backgroundColor=[UIColor clearColor];
doneButton = [[UIBarButtonItem alloc]initWithTitle:#" Done " style:UIBarButtonItemStyleBordered target:self action:#selector(doneButtonClick)];
self.navigationItem.leftBarButtonItem =doneButton;
webView.backgroundColor=[UIColor clearColor];
NSLog(#"File Name is %#",fileName);
NSLog(#"Enterning in the ImageSection");
NSString *ImageURL = fileName;
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
pictureImageView.image = [UIImage imageWithData:imageData];
Instead of this if i want to give from local like below then also it does not show image in imageView any idea how to load image from url thank
pictureImageView.image=[UIImage imageNamed:#"starblue.png"];
First set frame of that image and then write this line after add image in pictureImageView
[self.view bringSubviewToFront:pictureImageView];
Code looks fine
Things to check
Url contain a valid image
Set ImageView alloc it properly set frame and then add image
UIImageView *pictureImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 50, 50)];
Then do the rest
This is synchronous image loading that will block the main thread activities.Prefer to use asynchronous image download using AFNetworking or AsynchImageview
Use this code for show image in Url .
NSString *image=[NSString stringWithFormat:#"Your URL"] stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
NSLog(#"%#",image);
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:image]];
Yourimageview=[UIImage imageWithData:imageData];
pictureImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgurl]]];
Related
I have a NSMutableArray where it stores url to a image. And this NSMutableArray is called userPic. From my server it only prints out the url: not JSON or anything, only the url.
I can see in the output in Xcode that it shows the url, but how to I get this url in userPic to a background? Im trying to addSubView with the image for a background.
If something is unclear, sorry about that. Just let me know.
Please try to use this one.And i think your URL at index 0 of your array.
NSURL *imgURL = [NSURL URLWithString:[userPic objectAtIndex:0]]; // put your particular index where your image url in your array...
NSData *imgData = [[NSData alloc]initWithContentsOfURL:imgURL];
UIImage *img = [UIImage imageWithData: imgData];
[newView setBackgroundColor:[UIColor colorWithPatternImage:img]]
I want to get image from a php file (for example: http://abc.xyz.com/api/showImage.php) for a specific user through the user id & set the image in the image view of my iOS app. How can i do so?
Thanks in advance.
You can get the image from the above URL in the form of NSData :
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL urlWithString:#"http://abc.xyz.com/api/showImage.php"]];
UIImageView *imageView = [UIImageView alloc] initWithImage:[UIImage imageWithData:imageData]];
Its better to use Asyn download method when displaying images from the web.
You could create your own category on UIImageView or use the popular ones out there
SDWebImage.
[imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
Store response into array and then into an object say profile Object.I am using SDWebImage.
if U are geting image url at detailsObj.profileImage.Then use like below to set to imageview..
NSLog(#"response is:%#",userDetailsArray);
ProfileObject *detailsObj=[userDetailsArray objectAtIndex:0];
//in place of detailsObj.profileImage use url server link which is getting image.
if([detailsObj.profileImage isEqualToString:#""] || [detailsObj.profileImage isKindOfClass:[NSNull class]] || detailsObj.profileImage.length==0)
{
self.profileImageView.image=[UIImage imageNamed:#"NoImage.png"];
}
else
{
//without using SDWebImage
[self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage]];
//if it is NSData getting from server
self.profileImageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL urlWithString:detailsObj.profileImage]]];
//or using SDWebImage
[self.profileImageView setImageWithURL:[NSURL URLWithString:detailsObj.profileImage] placeholderImage:[UIImage imageNamed:#"NoImage.png"]];
}
I have a window in which I want to display an image in a specific block of that window. The image is retrieved from the local XML file. I parsed the XML file and got the image value in the log, but I don't know how to put it in that specific block. The below image pasted for the reference.
The arrow mark represents that within this UIImageView I need to get the image. Also, I doubt that I need to mention any name for reference to UIIMageView in storyboard. Suggest me an idea.
Edited
My parser code:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"Sample.xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
[xmlParser setDelegate:theParser]
After this I am using this code for getting image:
UIImage *image = [UIImage imageWithContentsOfFile:#"/Users/administrator/Desktop/imageApp/resources/Main_pic1.png"];
After this I don't know how to continue.
Yes, you have to create IBOutlet in .h file
like IBOutlet UIImageView *imgview; and connect imgview with your UIImageview from xib.
After that you can set image to image view.
NSURL *URL = [NSURL URLWithString:[your url which u get form local xml]];
NSData *imageData = [NSData dataWithContentsOfURL:URL];
UIImage *image = [UIImage imageWithData:imageData];
imgview.image=image;
Ttry this, It may help you.
You can directly pass the url image to Uiimageview by :
YourImageView.image = [UIImage imageWithContentsOfURL:YourUrl];
It's possible to do the equivalent by going through NSData, but it's a bad idea. Instead, the image should be downloaded asynchronously using NSURLConnection, and only once it's fully downloaded should it be converted into a UIImage and assigned to the image view.
Save all your urls in an say NSMutableArry *UrlArray then
int x = 0;
int y = 10;
for (int i = 0; i< [UrlArray]; i++)
{
UIImageView *imageView = [[[UIImageView alloc]initWithFrame:CGRectMake(3+x,y, 80,
80)]autorelease];
imageView.backgroundColor = [UIColor blueColor];
if (x >= 300)
{
x = 0;
y = y+imageView.frame.size.height+3;
imageView.frame = CGRectMake(x+3 , y, 80, 80);
}
CIImage *beginImage = [CIImage imageWithContentsOfURL:[UrlArray ObjectAtIndex:i]];
imageView.image = [UIImage imageWithCIImage:beginImage];
x = x+imageView.frame.size.width+5;
[self.view addSubview:imageView];
}
will do the work i guess;
I have array of image url. I want to show the images into UIImageView.
Now I convert the URL to NSData and then convert that into UIImage and then try to load that into UIImageView.
But it takes a lot of time to do this.
Is there a better way where in I can load the images in a faster and better manner?
Despite all of the answers on here telling you to do this in one line of code, it will sadly make no difference to the URL connection speed OR data / image decoding. If you want a faster way to TYPE the code then fine, but I would use category added to UIImageView....
#interface UIImageView (URL)
- (void)loadFromUrl:(NSString *)aUrl;
#end
#implementation UIImageView (URL)
- (void)loadFromUrl:(NSString *)aUrl {
NSURL *url = [NSURL urlWithString:aUrl];
NSData *data = [NSData dataWithContentsOfURL:url]
UIImage *image = [UIImage imageWithData:data];
if(image != nil) {
[self setImage:image];
}
}
#end
Now you can include the header and do...
[myImageView loadFromUrl:#"http://myurl.com/image.jpg"];
For more categories (I will be adding this one to my list!) check here. Those are all my useful ones, you may find them useful too! :)
Use everything in a single statement.
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:MyURL]]];
[UIImage imageWithData:[NSData dataWithContentsOfURL:]]
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageUrl]];
try this:-
image is UIImage and imageView is UIImageView
NSData *receivedData = [NSData dataWithContentsOfURL:#"yoururl"];
self.image=nil;
UIImage *img = [[UIImage alloc] initWithData:receivedData ];
self.image = img;
[img release];
[self.imageView setImage:self.image];
I've got some code to load an image from a URL, it seems to work ok. Unless the URL contains curly brackets. This seems like it is a string formatting problem? I can't figure it out.
ex
#"http://site/image.png //works
#"http://site/{image}.png //doesn't work
NSString* mapURL = #"http://site.com/directory/{map}.png";
NSLog(mapURL);
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
[imageView setImage:image];
[imageData release];
[image release];
thanks
i found this helpful
http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/