Re: Manipulating images with meta-data
Re: Manipulating images with meta-data
- Subject: Re: Manipulating images with meta-data
- From: "Ken Ferry" <email@hidden>
- Date: Tue, 3 Jun 2008 20:53:08 -0700
Can we see the code you're using to write the CGImage to the CGImageDestination?
I suspect the difficulty may be that you expect the metadata to be
carried with the CGImage. It isn't: You can get all the metadata
with CGImageSourceCopyPropertiesAtIndex, then you need to turn around
and pass metadata in to CGImageDestinationAddImage as the properties
argument.
Also, the CGImage you get out of the CGImageSource will behave like
your client's old hardware, in that it will not already incorporate
the orientation metadata. If you wanted to draw the CGImage 'right
side up', you'd need to look at the orientation information copied out
with CGImageSourceCopyPropertiesAtIndex and take it into account.
Last, I think rotation can be performed losslessly on a JPEG, but not
with anything that ships on current versions of Mac OS X. If that's
important, you still might want an external library.
-Ken
On Tue, Jun 3, 2008 at 10:14 AM, Randall Meadows <email@hidden> wrote:
> [Sorry for the length, but I've tried to include as much detail as necessary
> in order to get the best answer.)
>
> My program captures images from a digital camera. Said camera is *always*
> oriented in a portrait fashion, and the image is created by the camera (as a
> JPEG) with the appropriate EXIF meta-data that reflects this fact
> (orientation = 8).
>
> My client has some old hardware that doesn't understand (more accurately,
> doesn't even look at) the meta-data of the image, and chokes on image files
> that aren't "normalized" (orientation = 1). So my task is to re-orient the
> images so this hardware doesn't choke, but also fixes the meta-data so that
> all data remain consistent (so that programs that DO respect the meta-data
> will still work with the image correctly).
>
> Why, on a platform known for its graphics-handling capabilities, is this so
> frickin' hard?! :)
>
> A pristine JPEG downloaded from the camera has a wealth of information
> stored in meta-data; specifically, when viewed in Preview.app, the "More
> Info" pane has 5 tabs (GPS, General, Canon, Exif, TIFF), with a total of 53
> properties, NOT including the GPS info.
>
> In order to rotate the image and fix the orientation meta-data, I've tried
> several variations and permutations of:
>
> 1. Create an NSImage from the file;
> 2. Create a CGImageSourceRef from the file;
> 3. Create a CGImageSourceRef from the NSImage's TIFFRepresentation data;
> 4. Rotate the image;
> 5. Write out the file with a CGImageDestination thingie
>
> The best I've managed to do in the way of preserving the meta-data was a
> sequence of 1, 4, 3, 5. When I look at the resulting image in Preview.app,
> a vast majority of the meta-data is gone, gone, gone: a grand total of 16
> properties in categories General, JFIF, Exif, and TIFF. The greatest loss
> is nearly all the Exif data, which includes such important information as
> date/time captured, exposure, ISO, shutter speed, gamma, etc. From the
> original 34 Exif properties, all I'm left with is Pixel X|Y Dimentions!
> Even looking at the properties of the CGImage after completing step (3),
> that's all there is. AND, if I omit the rotation step, the resulting
> CGImage "orientation" property is still set to 1 (which I know to be an
> outright lie). WTF?!
>
> I'm about to resort to using a third-part solution (jpegtran and
> jpegexiforient) that I've found, but Shirley, I must be missing something in
> the Cocoa/Carbon/Foundation/whatever frameworks that would make my life a
> lot simpler. Am I right? Or is image manipulation on the Mac really this
> difficult for programmers?
>
> (Note: NO PART of this particular process involves actually *displaying* the
> image; that comes later, and will involve the already-processed image file.)
>
> Thanks for sticking with me this far, and thanks in advance for any help!
> randy
> _______________________________________________
>
> 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
>
_______________________________________________
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