Save Image From UIWebView into Photo Library in iOS - ios

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.

Related

How to load url link to imageview properly and how to manage the image in cache?

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 dispatch on image view

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);

Save image into library directly from APNS

i want to save image into photo library of iphone sdk. my image is coming from one url and that url is coming from APNS. basically i want save image directly into iphone lib without opening app when user will click on that URL which is coming as Push notification. right now i am doing this as follows but i dont want to show that image i just want to save.
-(void) sshowansimage:(NSString *) strImageURL
{
NSURL *imageURL = [NSURL URLWithString:strImageURL];
NSLog(#"coming URL is %#", strImageURL);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSData *imageData = [NSData dataWithContentsOfFile:strImageURL];
[self performSelectorOnMainThread:#selector(showImage:) withObject:imageData waitUntilDone:YES];
});
}
-(void)showImage:(NSData*)imageAsData
{
NSLog(#"IN image view mthhod data is %d",imageAsData.length);
ansinage.image = [UIImage imageWithData:imageAsData];
}
you can use your image as NSData and store it to albums with following.first you need to convert your NSData in to image object and then do following.
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
Use below code for store image directly to Photo Album
UIImage *image=[UIImage imageWithData: imageData];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

Random URL website address from core data that holds a picture to display in UIImage in iOS?

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.

UIImage return Null IOS

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.

Resources