Marc
Marc

Reputation: 1049

Save NSMutableData representing an image to the iPhone photo library

I have a NSMutableData containing a JPEG that I want to save in the device library.

I can do it converting it to an UIImage, but then it loses the EXIF data, so UIImaes should be avoided.

EDIT To reflect what I am trying to accomplish

I am using the iphone-exif library to edit the metadata of a picture in my main bundle. I want to save the resulting image in the photo library

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"P1080330" ofType:@"JPG"];  
NSData *uiJpeg = [NSData dataWithContentsOfFile:filePath];  
EXFJpeg* jpegScanner = [[EXFJpeg alloc] init];
[jpegScanner scanImageData: uiJpeg];
NSLog(@" EXIF_Make   %@ ", [ jpegScanner.exifMetaData tagValue: [NSNumber numberWithInt:EXIF_Make]]); // OUTPUTS PANASONIC

// Change camera maker to FairyGodmother
[jpegScanner.exifMetaData addTagValue: @"FairyGodmother" forKey:[NSNumber numberWithInt:EXIF_Make]];

NSMutableData *newImageData = [[NSMutableData alloc] init];
[jpegScanner populateImageData:newImageData];

// NOW I HAVE THE NSMUTABLEDATA CONTAINGING MY IMAGE WITH ALL MY EXIF DATA. HOW DO I PUT IT TO THE PHOTO LIBRARY?

Upvotes: 1

Views: 539

Answers (2)

Ben Zotto
Ben Zotto

Reputation: 71008

UIImageWriteToSavedPhotosAlbum (which takes a UIImage) is the only documented path to getting an image in the device's photo library, as far as I know.

What is your concern with "losing EXIF data"? Are you talking about orientation? (UIImage should take care of that for you.) Or other EXIF data?

The only way you can get an image out of the photo library is as a UIImage also, so I'm not sure what you stand to gain by shoving a raw JPEG stream into the library.

Upvotes: 2

Bruno Leite
Bruno Leite

Reputation: 1477

To Write a File use:

[yourImage writeToFile:filePath atomically:YES];

[]'s

Upvotes: -1

Related Questions