我想用 EXIF 将 alasset imagearray 直接保存到文档目录 我尝试了 PNG 转换,jpeg 转换没有任何效果它只是用 jpg 或 png 创建新图像(exif 丢失)
我已经看到一些时间将 NSData 直接保存到文件夹以保存 EXIF 不知道如何
我从 ALAsset 对象结果中获取元数据
NSDictionary *metadata = [[result defaultRepresentation] metadata];
另一个包含所有图像列表的资产数组
ALAssetsGroupEnumerationResultsBlock assetEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
[assets addObject:result];
;
NSLog(@"assets %i",[assets count]);
self.progressView.progress = (float)index / ([assets count]-1);
}
将图像保存到文档目录文件夹
-(void)saveImagesToDocumentDirectory{
NSLog(@"assets count %i",[assets count]);
for(int i=0;i<[assets count];i++)
{
currentImage = [UIImage imageWithCGImage:[[[assets objectAtIndex:i] defaultRepresentation] fullResolutionImage]];
[self saveImage:currentImage withImageName:[NSString stringWithFormat:@"Images %d",i]];
} }
- (void)saveImage:(UIImage*)image withImageName:(NSString*)imageName {
NSData *imageData = UIImagePNGRepresentation(image); //convert image into .png format.
// NSData *imageData = UIImageJPEGRepresentation(image,1.0);
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"MyFolder"];
NSString *fullPath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", imageName]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
NSLog(@"image saved");
}