6

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!

user2786
  • 656
  • 4
  • 13
  • 35
  • @MidhunMPThanks for the quick reply, but for me it's very important to change image name. Any other way to do the same, if possible? – user2786 Mar 27 '14 at 11:46
  • go thorough this link http://stackoverflow.com/questions/178915/how-to-save-picture-to-iphone-photo-library – Sukeshj Mar 27 '14 at 11:48
  • Thanks @Sukeshj, but UIImageWriteToSavedPhotosAlbum is only for saving image to the Camera Roll not in a specific Album. – user2786 Mar 27 '14 at 11:53
  • @user2786: What is the purpose of renaming the file, may I know that ? SO that I can specify any alternative – Midhun MP Mar 27 '14 at 11:53
  • @MidhunMPYes sure.. bcos of the slow net, some clients are not able to upload the images so i am uploading image reference to the server and full images i am saving in the device gallery. So they can easily find out that which image is related to which store fields? – user2786 Mar 27 '14 at 11:56
  • The asset URL uniquely identifies the image so why do you need to rename it? – Wain Mar 27 '14 at 11:58
  • @WainThanks please check your's before comment..i have given the reason. – user2786 Mar 27 '14 at 12:15
  • I want to rename the photos so I can search them more easily. At least if not rename, then add Tags like Flickr allows which I can easily search through. – Farhad Oct 27 '16 at 09:00

3 Answers3

2

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/ .

Yonat
  • 4,382
  • 2
  • 28
  • 37
0

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...

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
  • @FahimThanks, but my requirement is to save all captured images into device gallery with a specific file name as i have mentioned in my question. So for saveImage: toAlbum: withCompletionBlock method, i need to change save image filename before calling this method.. – user2786 Mar 27 '14 at 11:50
  • then define the new file name and use it... do you have problem in defining new file name? – Fahim Parkar Mar 27 '14 at 11:53
  • You don’t have permission to save the file “ customImageFilename.jpg” in the folder “100APPLE" :/ – Jirson Tavera Sep 17 '16 at 02:59
0

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

    }

Community
  • 1
  • 1
Anindya Sengupta
  • 2,539
  • 2
  • 21
  • 27
  • @AnindyaThanks alot..even still i am searching for the same. My requirement is to save all captured images into device gallery with a specific file name.. – user2786 Mar 27 '14 at 13:03
  • Changing name seems to be not possible at all. You have to depend on `AssetLibrary`. However you can change the metadata if that somehow suits your need. Metadata includes information like description, camera, location etc. Here is how to do it: [link](http://www.altdevblogaday.com/2011/05/11/adding-metadata-to-ios-images-the-easy-way/) For that you will have to use `– writeImageDataToSavedPhotosAlbum: metadata: completionBlock:` – Anindya Sengupta Mar 27 '14 at 13:23
  • @AnindyaBut using writeImageDataToSavedPhotosAlbum: metadata: completionBlock:, we cant save photo in a specific folder Album on device..it will save in Camera Roll only... – user2786 Mar 28 '14 at 05:27
  • Visit this: http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/ It has got a demo (essentially a Category) which shows how to save to to custom photo library using the `writeImageDataToSavedPhotosAlbum: metadata: completionBlock:` method – Anindya Sengupta Mar 28 '14 at 15:14