简体   繁体   English

将代表图像的NSMutableData保存到iPhone照片库

[英]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. 我有一个NSMutableData,其中包含要保存在设备库中的JPEG。

I can do it converting it to an UIImage, but then it loses the EXIF data, so UIImaes should be avoided. 我可以将其转换为UIImage,但随后它将丢失EXIF数据,因此应避免UIImaes。

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. 我正在使用iphone-exif库来编辑主捆绑包中图片的元数据。 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. UIImageWriteToSavedPhotosAlbum (带有UIImage)是在设备的照片库中获取图像的唯一记录路径。

What is your concern with "losing EXIF data"? 您对“丢失EXIF数据”有何担忧? Are you talking about orientation? 您在谈论方向吗? (UIImage should take care of that for you.) Or other EXIF data? (UIImage应该为您解决这个问题。)还是其他EXIF数据?

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. 你可以得到一个图像出来的照片库的唯一方式是一个UIImage还,所以我不知道你站在搡原始JPEG流进库,以获得什么。

To Write a File use: 要写入文件,请使用:

[yourImage writeToFile:filePath atomically:YES];

[]'s []的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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