Phonegap (cordova) save image to custom album - ios

I do not know much about Objective-C.
I need to save the image in the gallery to custom name album and i used Canvas2ImagePlugin but image save to album camera roll.
Canvas2ImagePlugin using:
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
How to use the name album in the function UIImageWriteToSavedPhotosAlbum? Or use another function?

Actually i don't know about phonegap. but i can give you hint that how we can achieved in ios. with help of ALAssetsLibrary, we can stored photo to custom album.
[self.library saveImage:image toAlbum:#"Touch Code Magazine" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
}
}];

Related

copy image from sandbox and paste it to iPad/ iphone internal memory

I've using uiimagepickercontroller and taken images via camera and stored into folder that was created in sandbox. That stored images are not displayed in iPads or iPhone photo gallery. I want to display those sandbox pictures in device gallery. Any one help me out from this.
My optimum goal is to copy image from sandbox and paste it to device's internal memory.
You use the UIImageWriteToSavedPhotosAlbum() function.
UIImageWriteToSavedPhotosAlbum(IMAGE_TO_STORED, nil, nil, nil);
Edit:
- (IBAction)savedPhoto:(id)sender{
UIImageWriteToSavedPhotosAlbum(IMAGE_TO_STORED, nil, nil, nil);
}
Another way to stored image is:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library saveImage:image toAlbum:nil withCompletionBlock:^(NSError *error) {
if (error!=nil)
{
NSLog(#"Error: %#", [error description]);
}
}];

iOS - Is it possible to rename image file name before saving it into iPhone device gallery from app?

Hey I'm new to iPhone and I have been trying to make an gallery kind of app. Basically, what I want to do is that i need to save all the captured images into a specific folder like a new album "My_App Images" related to our app name in iPhone device gallery, it's working for me, but I am having trouble to change the image file name, i don't know that Is it possible to specify a file name? Using iPhoto, currently i am getting image file name as "IMG_0094.jpg", can we change it with any other file name like "Anyfilename.png" format programmatically?
here is my code for saving images to the specific album :
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[self.library saveImage:image toAlbum:#"My_App Images" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Image saving error: %#", [error description]);
}
}];
[picker dismissViewControllerAnimated:NO completion:nil];
}
Any source or link for reference is appreciated. Thanks for the help!
There is a way to kinda do that, by setting the image IPTC metadata field "Object Name". If you later import the image to iPhoto, then this name will be used as its title.
See details (and code) at http://ootips.org/yonat/how-to-set-the-image-name-when-saving-to-the-camera-roll/ .
Do you meant,
// Build NSData in memory from the btnImage...
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
// Save to the default Apple (Camera Roll) folder.
[imageData writeToFile:#"/private/var/mobile/Media/DCIM/100APPLE/customImageFilename.jpg" atomically:NO];
Now adjust the path of folder as per your folder name...
Sorry to disappoint you, but it seems that you can not change the name of the photos, before or after saving, in the photo album, custom or not. Here is a post to explain it:
iOS rename/delete albums of photos
Edit
So, to clarify my comment, use the following override:
Download the NSMutableDictionary category for metadata of image here.
Also download the sample project CustomAlbumDemo from here and modify the NSMutableDictionary+ImageMetadata.m file in the CustomAlbumDemo project as:
-(void)saveImage:(UIImage*)image toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
//write the image data to the assets library (camera roll)
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
NSMutableDictionary *metadata = [[NSMutableDictionary alloc] init];
[metadata setDescription:#"This is my special image"];
[self writeImageDataToSavedPhotosAlbum:imageData metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) {
//error handling
if (error!=nil) {
completionBlock(error);
return;
}
//add the asset to the custom photo album
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];
}];
}

How can I save and again load the images to and from iPad's Gallery

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

How to save photo in a particular album in iOS

I am using this code to save image into the album but images are being saved in Camera Roll album. I want to save images in WEAVE album. I'm using this code:
CGRect screenRect=CGRectMake(0, 0, viewPlay.frame.size.width, viewPlay.frame.size.height);
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx=UIGraphicsGetCurrentContext();
[[UIColor whiteColor] set];
CGContextFillRect(ctx, screenRect);
[self->viewPlay.layer renderInContext:ctx];
UIImage *screenImage=UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
UIGraphicsEndImageContext();
this code is working fine for me. please give me any suggestion what change i do here to save image into WEAVE folder.
You can use the following code for doing this:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library saveImage:image toAlbum:#"Midhun" withCompletionBlock:^(NSError *error) {
if (error!=nil)
{
NSLog(#"Error: %#", [error description]);
}
}];
Check this tutorial also: Custom Photo Album
For more info about ALAssetsLibrary

iOS: Store new photos using UIImagePickerController NOT in default album

I am using UIImageWriteToSavedPhotosAlbum to store a new photo on the iPhone (code see below).
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
This works fine. However I would like to store new photos in a different album. Not the default one.
EDIT
I am using the following block to create the album.
ALAssetsLibraryGroupResultBlock resultblock = ^(ALAssetsGroup *assetGroup)
{
[assetGroup addAsset:myasset]
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(#"in failureblock, got an error: %#",[myerror localizedDescription]);
};
[library addAssetsGroupAlbumWithName:name resultBlock:resultblock failureBlock:failureblock];`
I am using the UIImagePickerController. How do I get the asset of a new image? When/where do I call UIImageWriteToSavedPhotosAlbum to store it?
Since iOS 5 you can create a new album with addAssetsGroupAlbumWithName:resultBlock:failureBlock: using the ALAssetsLibrary
Here's a link to a detailed tutorial on how to do that — http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/

Resources