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);
Related
I was trying to put the htttp link to the UIimageView but it doesn't show up me an image. But when i point a local file in the local storage, it shows me the image. Please help me guys.
You should do something like this
__block UIImage *img;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *url = [NSURL URLWithString:#"some_link_to_image"];
NSData *data = [NSData dataWithContentsOfURL:url];
img = [[UIImage alloc] initWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
yourImageView.image = img;
});
});
You need to download it before displaying. You have different alternatives, you could use a Cocoa API or just an external library to manage the request.
One of the external libraries to handle HTTP requests is AFNetworking
In particular it offers a very convenient category UIImageView+AFNetworking.h You can use it like this:
#import "UIImageView+AFNetworking.h"
//...
NSURL *url = [NSURL URLWithString:#"http://here_your_url_to_the_image"];
[yourImageView setImageWithURL:url];
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) {
// ...
}
The app uses a series of jpg's and a timer that steps through them to make an animation.
During the animation on the device, it crashes (didReceiveMemoryWarningError.)
I'm new to iPhone programming and Objective-C. How can I optimize this flipbook for the iPhone?
I can imagine simply compressing the jpeg's and perhaps losing some quality would help, but my understanding is the iPhone does its own image compression/decompression on the device and I may be wasting my time.
Tried different things, eventually hit on storing an array of NSData objects and converting to UIImage on the fly.
for (NSString *imageFile in directoryList) {
NSString *fileLocation = [imageFolder stringByAppendingPathComponent:imageFile];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
if (imageData) {
[images addObject:imageData];
} else {
[Util trace:#"cannot get image data for image named: %#", fileLocation];
}
and then to update your image:
-(void)updateImageView:(id)sender
{
UIImage *anImage = [UIImage imageWithData:[images safeObjectAtIndex:nextImage] ];
[imageView setImage:anImage];
nextImage++;
}
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.
I want to save image from UIWebView into Photo Library in iOS app.
I also read [http://stackoverflow.com/questions/6766671/how-to-saving-uiwebview-content-into-photo-library][1]
But i can't save.
i wrote following codes in save method.
- (IBAction)saveImage:(id)sender
{
NSString *sizeOfImageByJs = [NSString stringWithFormat:#"document.body.scrollWidth;"
"document.body.scrollHeight;"
"window.innerWidth;"
"window.innterHeight;"];
NSString *urlToSave = [webViewOfPhoto stringByEvaluatingJavaScriptFromString:sizeOfImageByJs];
NSURL *imageUrl = [NSURL URLWithString:urlToSave];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
UIImage *image = [UIImage imageWithData:imageData];
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}
It's doesn't save anythings.
How to save it?
Thanks.