Mailing Lists: Apple Mailing Lists

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

Re: How to grab IconRef from a .tiff file.



On 20/08/2003 01:45, "Jiang, Juwan" <email@hidden> wrote:

> I want to use ImageWell to show a Image.
> I want to grab the IconRef from a .tiff file and show it into ImageWell.
>
> I do not let user select the file, but bundle the .tiff file into resource.
> Then I can call CFBundleCopyResourceURL to get the URL of the file.
> So what I want to know is how to get the IconRef from the the file.

You may try the fragment below (untested). Basically it does
(tries to do):

FSRef-> FSSpec-> GraphicsImportComponent-> PicHandle->
-> IconFamilyHandle-> IconRef

// add error checking
IconRef FileToIconRef(FSRef *fsRef)
{
GraphicsImportComponent component;
OSStatus err;
FSSpec fsSpec;
PicHandle pict;
IconFamilyHandle iconFamily;
IconRef iconRef;
const OSType kFakeCreator = '#%$^', kFakeType = '#$&$';

err = FSGetCatalogInfo(fsRef, kFSCatInfoNone, NULL,
NULL, &fsSpec, NULL);

err = GetGraphicsImporterForFile(&fsSpec, &component);
err = GraphicsImportSetGraphicsMode(component,
graphicsModeStraightAlpha, NULL);
err = GraphicsImportGetAsPicture(component, &pict);
CloseComponent(component);

iconFamily = (IconFamilyHandle)NewHandle(0);
err = SetIconFamilyData(iconFamily, 'PICT', (Handle)pict);
KillPicture(pict);
err = RegisterIconRefFromIconFamily(kFakeCreator, kFakeType,
iconFamily, &iconRef);
DisposeHandle((Handle)iconFamily);
err = AcquireIconRef(iconRef);
err = UnregisterIconRef(kFakeCreator, kFakeType);
return iconRef;
}

Mike
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.



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.