11

Is there any way to write a UIImage to a JPG/PNG file and then append metadata to it? I know you can use:

writeImageDataToSavedPhotosAlbum:metadata:completionBlock

to do this in the Saved Photos, but how do you do the same thing directly to a file? I can't seem to find any way to do this. I know that UIImagePNGRepresentation() and UIImageJPGRepresentation() will give you NSData that you can use to write the file, but there's no way to append/replace the metadata in the file.

Any ideas?

rekle
  • 2,375
  • 1
  • 18
  • 9
  • 3
    Perhaps this answer to a similar question will help: http://stackoverflow.com/questions/5125323/problem-setting-exif-data-for-an-image/5294574#5294574 – Greg Mar 16 '11 at 19:50
  • 1
    Writing a custom PNG exporter is a matter of 3 days, anyway :) – Sulthan Nov 01 '11 at 16:40
  • You should take a look at ImageIO framework for that. You can add metadata to `CGImageDestination` using `CGImageDestinationSetProperties` and then get the raw data from it – Voda Ion Sep 24 '13 at 14:14

2 Answers2

3

Looks like a duplicate.

To add metadata to a UIImage you can use the ImageIO framework You can create a CGImageDestination object from a UIImage, add metadata to it using CGImageDestinationSetProperties and then get the raw data (which includes the compressed image and the metadata) from it.

Community
  • 1
  • 1
NSMutableString
  • 10,493
  • 1
  • 21
  • 27
-7

@rekle Check it out this code is for writing the photo in to file

NSData *imageData = UIImagePNGRepresentation(self.imageView.image);
            NSData *myImage=[[NSData alloc]initWithData:imageData];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentsDirectory = [paths objectAtIndex:0];
            NSLog(@"%@",documentsDirectory);

            NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",camtitle.text]];
            [myImage writeToFile:fullPathToFile atomically:YES];
            NSLog(@"%@",fullPathToFile);
            [myImage release

];

Harish
  • 544
  • 3
  • 17