On Apr 3, 2008, at 2:13 AM, Trygve Inda wrote:
If you just need to display the image, use an NSImage
(initWithContentsOfFile).
If you need a greater control over metadata, use the ImageIO API
(search CGImageSource in doc and sample codes).

This works and retrieves the user text that was embedded in the image). Is there a more Cocoa-way to do this ather than having to use QuickTime and
FSSpecs?

I don't know about detaching from QuickTime, but you can at least get rid of the FSSpec parts:

GraphicsImportComponent  tGIC;
ComponentResult          result;
UserData                 myUD;
Handle                   dataHandle;
CFStringRef              cfString = nil;
FSRef                    theFSRef;
OSErr                    err;

Handle                   dataRef;
OSType                   dataRefType;

CFURLGetFSRef ((CFURLRef) [NSURL fileURLWithPath:path], &theFSRef);

result = QTNewDataReferenceFromFSRef(&theFSRef, 0, &dataRef, &dataRefType);
if (result == noErr)
{
result = GetGraphicsImporterForDataRef(dataRef, dataRefType, &tGIC);
    if (result == noErr)
    {

 err = NewUserData(&myUD);
 if (!err)
 {
  result = GraphicsImportGetMetaData (tGIC, myUD);
  if (result == noErr)
  {
    dataHandle = NewHandle (0);
    if (dataHandle)
    {
err = GetUserDataText (myUD, dataHandle, kUserDataTextComment, 1, 0);
     if (!err)
     {
       HLock (dataHandle);
cfString = CFStringCreateWithBytes (kCFAllocatorDefault, (UInt8 *) (*dataHandle), GetHandleSize(dataHandle), kCFStringEncodingMacRoman, false);
                }
            }
        }
    }


    }

    DisposeHandle(dataRef);
}

And a couple of other things I noticed:

- You could just use ComponentResult as your error/result variable type since it handles a superset of OSErr values.
- You're not calling DisposeHandle(dataHandle).


steve

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to