IOS Can I rename the image file name before saving it to the iPhone device gallery from the application?

Hey, I'm new to the iPhone, and I'm trying to create a gallery app. Basically, I want to need to save all the captured images to a specific folder, for example, the new album "My_App Images" associated with our application name in the iPhone device gallery, it works for me, but I am having problems changing the name image file, I do not know that you can specify the file name? Using iPhoto, I am currently getting the image file name as "IMG_0094.jpg", can we change it with any other file name, for example, "Anyfilename.png", programmatically?

here is my code for saving images to a 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];
}

. !

+4
3

,

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

...

0

, , , , , , . , :

iOS /

Edit


, , :

  • NSMutableDictionary .
  • CustomAlbumDemo NSMutableDictionary+ImageMetadata.m CustomAlbumDemo:

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

    } >

0

Source: https://habr.com/ru/post/1533716/


All Articles