• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting NSDate from EXIF of a image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting NSDate from EXIF of a image


  • Subject: Re: Getting NSDate from EXIF of a image
  • From: Jushin <email@hidden>
  • Date: Mon, 2 Mar 2009 23:48:23 -0500

I found that in order to convert NSString format of date to NSDate, we
need timezone.
But, EXIF doesn't support timezone unless GPS tags exist.
So, here is what I have come up with:

NSDictionary *metadata = (NSDictionary *)
CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
NSMutableDictionary *muMetadata = [[metadata mutableCopy] autorelease];
[metadata release];

NSMutableDictionary *EXIFDictionary = [[[muMetadata
objectForKey:(NSString *)kCGImagePropertyExifDictionary]
										mutableCopy] autorelease];

NSString *EXIFDate = [[EXIFDictionary objectForKey:(NSString
*)kCGImagePropertyExifDateTimeDigitized] retain];

NSArray *listItems = [EXIFDate componentsSeparatedByString:@":"];

NSString *newFormatedDate = [NSString stringWithFormat:@"%@-%@-%@:%@:%@ %d",
									 [listItems objectAtIndex:0], [listItems objectAtIndex:1],
[listItems objectAtIndex:2],
									 [listItems objectAtIndex:3], [listItems objectAtIndex:4],
									 (([[NSTimeZone systemTimeZone] secondsFromGMT]/60)/60)];

NSDate *aDate = [[NSDate alloc] initWithString:newFormatedDate];

I still think these are not clever way. If you have better idea,
please share it with me :)

On Mon, Mar 2, 2009 at 10:00 PM, Jushin <email@hidden> wrote:
> I need to get time and date from EXIF of a image.
> Following is the code snippet I used:
>
> NSDictionary *metadata = (NSDictionary *)
> CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
> NSMutableDictionary *muMetadata = [[metadata mutableCopy] autorelease];
> [metadata release];
>
> NSMutableDictionary *EXIFDictionary = [[[muMetadata
> objectForKey:(NSString *)kCGImagePropertyExifDictionary]
>                                                                                mutableCopy] autorelease];
>
> NSString *EXIFDate = [[EXIFDictionary objectForKey:(NSString
> *)kCGImagePropertyExifDateTimeDigitized] retain];
> NSLog(EXIFDate);
>
> NSDate *aDate = [[NSDate alloc] initWithString: EXIFDate];
>
>
> Here are my questions:
>
> 1. the last line, NSDate *aDate returns null.
> I think it is because the format of EXIFDate string that was created
> right above isn't correct.
> When I did NSLog(EXIFDate), I get followings:
> 2008:11:06 19:12:51
>
> According to the NSDate documentation, string format of time should be:
> 2008-11-06 19:12:51
>
> 2. the returned date string (EXIFData) doesn't have timezone information.
> Is it possible to get timezone info as well from the EXIF information?
>
> 3. Well... eventually what I want to do is, I want to create "unix
> time" format of date from image EXIF using timeIntervalSince1970.
> Is there any other better way to get this?
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Getting NSDate from EXIF of a image
      • From: Nathan Vander Wilt <email@hidden>
References: 
 >Getting NSDate from EXIF of a image (From: Jushin <email@hidden>)

  • Prev by Date: Path for writeToFile
  • Next by Date: Re: Do I need to relase @"string" ??
  • Previous by thread: Getting NSDate from EXIF of a image
  • Next by thread: Re: Getting NSDate from EXIF of a image
  • Index(es):
    • Date
    • Thread