How to update exif of ALAsset without changing the image?

随声附和 提交于 2019-12-06 06:13:24

问题


I use setImageData:metadata:completionBlock: of ALAsset to update the exif(metadata) of an asset.

I just want to update the metadata, but this method require an imageData as the first parameter. I use the code below to generate imageData, but it modified my image(I checked the file size and file hash).

ALAssetRepresentation *dr = asset.defaultRepresentation;
UIImage *image = [UIImage imageWithCGImage:dr.fullResolutionImage scale:dr.scale orientation:dr.orientation];
NSData *data = UIImageJPEGRepresentation(image, 1);

Is there any other method I could use to update just the exif of an ALAsset? Or any way to generate the right imageData for method setImageData:metadata:completionBlock: ?


回答1:


I found a way to generate imageData. Code below:

Byte *buffer = (Byte *)malloc(dr.size);
NSUInteger k = [dr getBytes:buffer fromOffset:0.0 length:dr.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:k freeWhenDone:YES];

So I can use the data above with setImageData:metadata:completionBlock: to update only the exif of ALAsset.



来源:https://stackoverflow.com/questions/11520209/how-to-update-exif-of-alasset-without-changing-the-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!