简体   繁体   中英

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?

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.

To Write a File use:

[yourImage writeToFile:filePath atomically:YES];

[]'s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM