4

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: ?

nickcheng
  • 516
  • 4
  • 22

1 Answers1

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.

nickcheng
  • 516
  • 4
  • 22
  • Could someone explain what this does? How does this not update the image? – akaru Sep 15 '12 at 02:59
  • @akaru, the above code gets the raw image data before it becomes a CGImage. When writing via `setImageData:...`, the image is unmodified. – Brian Nickel Jan 09 '13 at 03:55