Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error Updating GPS Information



I have been attempting to update the GPS data of an image using an edit plugin but every time that the image file is written, the GPS data seems to disappear. I have hacked up the save code for SampleEditPlugIn and it still doesn't work. Has anyone had any success with modifing the GPS metadata?

Here is the code:

  CGImageSourceRef originalImageSource = CGImageSourceCreateWithURL((CFURLRef)imageURL, NULL);
  
  //get gps metadata
  NSDictionary *metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(originalImageSource,0,NULL);
   
  //make the metadata dictionary mutable so we can add properties to it
  NSMutableDictionary *metadataAsMutable = [[metadata mutableCopy]autorelease];
  [metadata release];
   
  //get mutable gps data
  NSMutableDictionary *GPSDictionary = [[[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy]autorelease];
  if(!GPSDictionary)
  {
        GPSDictionary = [NSMutableDictionary dictionary];
   }
   
  //set the longitude
  [GPSDictionary setObject:_longitude forKey:(NSString *)kCGImagePropertyGPSLongitude];
   
  //set the latitude
  [GPSDictionary setObject:_latitude forKey:(NSString *)kCGImagePropertyGPSLatitude];
   
  //add our modified GPS data back into the image's metadata
  [metadataAsMutable setObject:GPSDictionary forKey:(NSString *)kCGImagePropertyGPSDictionary];
  NSLog(@"Updated metadata: %@", metadataAsMutable);
           
   // Create a new image source that reads the TIFF data that we get from our NSImage.
   NSData *imageData = [newImage TIFFRepresentation];
   CGImageSourceRef finalImageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
           
   // Create an image destination. This will take the image data from our source, and write it along with the metadata we read above
   // into a file in the correct format.
   CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)imageURL, imageType, 1, NULL);
   CGImageDestinationAddImageFromSource(imageDestination, finalImageSource, 0, (CFDictionaryRef)metadataAsMutable);
           
   if (!CGImageDestinationFinalize(imageDestination))
   {
                // The sample code doesn't do any specific error handling in this case. This would be an appropriate
                // place to notify the user, put up an alert, etc.
    }

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Aperture-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/aperture-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.