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);
Related
I am newbiee to the backend. I have been working on an app collaborating with a newbiee backend developer. I am working on an application where a user sells/buys a product. I could able to send product the image which taken from the device camera and send it via POST method to database.
Taken image is stored in the database. The question that I have is as follows:
In order to get back this image to the app what method needs to be used? Is it better to get data chunk or image URL in JSON?
I would recommend getting the image URL and then using the following code to load the image:
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL:url];
if (data == nil) {
NSLog(#"Uh oh! Couldn't retrieve the image");
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageWithData:data];
//do something with the image such as:
UIImageView *myImageView.image = image;
});
});
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);
How can I save the images to iPad's Gallery, and again read them from there into my App.
Is it possible to create a folder structure in iPad's gallery where I could store images generated through my app.
Actually I am able to save the images to gallery, I am using this
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
But don't know how to load it back into app from gallery. ?
Use the ALAssetsLibrary, then you can call writeImageToSavedPhotosAlbum:metadata:completionBlock: to save the image and in the completion block you get the assetURL. This can later be used to get the image back from the library.
Docs are here .
To get the image for the asset url:
[self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset) {
if (asset != nil) {
imageView.image = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
}
} failureBlock:^(NSError * error) {
NSLog (#"Error getting image asset: %#", error);
}];
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.