NSURL *url = [NSURL URLWithString:
pictureUrl];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
NSLog(#"image width:%#",image.size.width);
I am getting null from this log? The image is valid and displaying correctly?.
This is in a table cell
Try this:
NSLog(#"image width:%f",image.size.width);
Besides that, I hope you are calling this on a background thread (not within cellForRow), otherwise loading your cells will be very slow and screw up user interaction.
Related
I have a method that I'm calling from cell in the viewForRowAtIndexPath method.
The method containts only this code
NSURL *imageURL = [NSURL URLWithString:urlString];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^(void){
completionBLock(image);
});
Images are loading very slowly and sometimes not at all. Everytime the cell goes back into view the method gets called again.
This is in my cellForIndexPathRow
[Method getImage:brochureModel.brochureCoverUrl Oncompletion:^(UIImage *image) {
cell.imageView.image = image;
}];
How can I download images from a url and display it in a collection view reusable cells.
Note: I'm trying to not use any third party libraries for my app
My problem is with the caching of the images. I tried this with self.imageCache being a mutableDictionary.
if (self.imageCache[urlString]) {
UIImage *imageFromCache = self.imageCache[urlString];
onImageDidLoad(imageFromCache);
} else {
[API fetchImageFromUrl:urlString onDidLoad:^(UIImage *image) {
self.imageCache[urlString] = image;
onImageDidLoad(image);
}];
}
NSString *img=[arrImages objectAtIndex:i];
imgScrollView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:img]]];
I have displayed my code. The URL links have been stored into an array and the images are also fetching into uiimage view, but only the first two images are loaded into the imageview while the others didn't load .
arrImages:
inside image viewhttp://localhost:8888/welcome/company/0/images/TV Repair.png
this is the link present in the arrImages i don't know why first two images has been loading.
FOR LOOP:
for(NSDictionary *DicHoleCategories in ArrCategory)
{
StrName=[DicHoleCategories objectForKey:#"image"];
if(StrName!=nil)
{
subimages=[NSString stringWithFormat:LocalImage"%#",StrName];
[DicAllValues setObject:subimages forKey:#"image"];
NSError *error =nil;
}
[arrImages addObject:[DicAllValues objectForKey:#"image"]];
}
Can anyone find the issue and help me please?
Go through the below coding
//url string
NSString *ImageURL = #"yoururl";
//string to data conversion
NSData *imagedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
//set image
imageView.image = [UIImage imageWithData:imageData];
please follow the below code
if(StrName!=nil)
{
subimages=[NSString stringWithFormat:LocalImage"%#",StrName];
[DicAllValues setObject:subimages forKey:#"image"];
NSError *error =nil;
[arrImages addObject:[DicAllValues objectForKey:#"image"]];//add here!
}
Plz check now and tell me if its working or not!
Online image speedily dispatch on Image-view.
dispatch_async(imageQueue, ^{
NSURL *url = [NSURL URLWithString:OBJPC.main_photo];
NSData *imageData = [[NSData alloc]initWithContentsOfURL:url ];
dispatch_async(dispatch_get_main_queue(), ^{
[cell.imgTitle setImage:[[UIImage alloc]initWithData:imageData ]];
});
});
This leads me to believe the large images taken by the iPhone are timing out over the somewhat slow 3G network. Is there any way to compress/resize the image from the iPhone before sending it?
Thanks!
Yes you can,
If the photos are taken on iPhone 5S, 6+ they can be really large 10MB+.
before you upload the photos, use:
UIImage *image = info[UIImagePickerControllerOriginalImage];
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
where the image is a UIImage object and the compressionValue is a percentage.
UIImageJPEGRepresentation(UIImage, compressionValue);
I'm working with a UICollectionView and I need to load images in to the collection cell.
Here is the code
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSURL *imageURL = [NSURL URLWithString:post.cover_img_url];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
[cell.cover_img setImage:image];
});
});
post.cover_img_url = the_url_for_the_image;
cell.cover_img = the_UIImageView_object;
When I set the image not from the web, it works perfectly.
But when I try from the web, the UIImageView is blank not image.
Anyone have any ideas?
Your code looks like it should be working, but there are a couple of things that you need to test. First, you need to check to make sure that imageURL is both non-nil, and points to exactly where you think it's pointing. Copy paste a log result to your desktop browser if you have to.
NSLog(#"%#",imageURL);
Second, in the event that fetching the image fails, you need to be able to detect this. I recommend that if you continue to use the dataWithContentsOfURL: route that you at least use the following to check the error:
NSError *error = NULL;
NSData *data = [NSData dataWithContentsOfURL:imageURL options:NSDataReadingMappedIfSafe error:&error];
if (error) {
// ...
}
I'm new to using xcode, so any information or links would be helpful. If I had a RANDOM website url in coredata, how would I be able to direct my UIImage to get the photo from that website to display in iOS?
Let's say imageURL is a NSString * ivar or property where you hold your URL.
To get the image this should work:
NSURL *url = [NSURL URLWithString:imageURL];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *myImage = [UIImage imageWithData: imageData];
Of course you should add some error checking but this should get you into the right direction.