I am Trying to integrate SdWebImage With Youtube Api for the purpose of Fetching thumbnail image to cache them so as get rid of scrolling problem in UITableView.Problem is Youtube API Provide a URL that is for Thumbnail NSDATA which can be converted back to UIImage object but SDWebImage is Takes URL to an image to manage images in best efficient method.
Youtube Api Method:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
UIImage * image = [UIImage imageWithData:data];
SDWebImage Method
[cell.imageView setImageWithURL:[NSURL URLWithString:[_objects objectAtIndex:indexPath.row]]
placeholderImage:[UIImage imageNamed:#"placeholder"]];
Please Tell How We Solve this Problem.
I think you are overthinking this problem. You should be able to just do this:
NSURL *thumbnailURL = [NSURL URLWithString:[[thumbnails objectAtIndex:indexPath.row] URLString]]];
[cell.imageView setImageWithURL:thumbnailURL
placeholderImage:[UIImage imageNamed:#"placeholder"]];
Related
I am getting strange issue please if get help from anyone then it'll be appreciated.
My problem is i am getting only Image names from server through web service for ex: abc.png.
Now that image need to be attached with the static URL & than it will be used to display to UIImageView.
I have used this code:
for (int i = 0; i<[[myDic valueForKey:#"posts"] count]; i++)
{
NSData *bgImageData = nil;
if ([[[[myDic valueForKey:#"posts"] objectAtIndex:i] valueForKey:#"post"] valueForKey:#"video_image"] == [NSNull null])
{
bgImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://drupal.org/files/issues/no-pre.png"]];
}
else
{
bgImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://sitebildz.com/application/document/video/%#",[[[[myDic valueForKey:#"posts"] objectAtIndex:i] valueForKey:#"post"] valueForKey:#"video_image"]]]];
}
[arrVideoImage addObject:bgImageData];
}
For Display in Table :
cell.imageView.image = [UIImage imageWithData:[arrVideoImage objectAtIndex:indexPath.row]];
But don't know why its not working.
Thanks.
As commented The Tiger, your best choice would be to use an external library like SDWebImage which can handle download, caching and display of online images.
Here is an example using this framework :
[imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
You can also use blocks to insert logic once an image finished loading :
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {... completion code here ...}];
You're doing wrong. See you're making NSData in loop. Do you think it will wait until image is download from server ??? Nope it will not wait. So in this case you're adding empty NSData.
Would be better to use SDWebImage.
1. Download it
2. Import it in your project
3. build project (success)
4. Import #import "UIImageView+WebCache.h" in your ViewController class
[cell.imageView setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:#"placeHolderImageName"]];
you cab use https://github.com/enormego/EGOImageLoading/tree/master/EGOImageView which will download the image from server in async way and display once it completely downloaded from server. It also cache that image so that multiple request can be avoided and it enhances the system.
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"]];
}
The code below works fine if I give statically but
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"http://4cing.com/mobile_app/uploads/pageicon/6.jpg"]]]];
Same code - I am passing the image url name dynamically it's not working
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]]]];
You need to verify the NSArray contents. Log out the objects of the array:
NSLog(#"imagename = %#",[imagename description]);
Also, a side-note - might want to think about loading that image dynamically. I wrote a class that makes this pretty painless:
https://stackoverflow.com/a/9786513/585320
The answer is geared toward using in TableViews (where lag would really hurt performance), but you can (and I do) use this for any web image loading. This keeps the UI fluid and is very fast.
NSMutableArray *imagename = [[NSMutableArray alloc] initWithObjects:#"http://4cing.com/mobile_app/uploads/pageicon/6.jpg", nil];
UIImageView *imgDescView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 200, 200)];
imgDescView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
[NSURL URLWithString:[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]]]]];
it is working ... i think u r not creating array properly.
Hi create url in this manner
[NSURL URLWithString:[[NSString stringWithFormat:#"%#",[imagename objectAtIndex:0]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
i think it will work and will resolve ur problem.
I want get image from public perfil of Facebook and show it in my iPhone. I'm using the Facebook Developer method "getPhoto" but I canĀ“t show any image?
Can someone help me?
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
As told Previously your problem to retrieve the object id. Here is the solution:-
To retrieve the images of your friend. Create the connection with the url
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/me/friends?access_token=%#",accessTokenValue];
above url when hit returns an array of dictionary in which name of your friend and his id is written. Just Json parse that you will get the id of the person.
you need to use graph api for this purpose
NSString *url = [[NSString alloc] initWithFormat:#"https://graph.facebook.com/%#/picture",objectID];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];