Re: Getting iPod icon, was Getting the network Machine Icon
Re: Getting iPod icon, was Getting the network Machine Icon
- Subject: Re: Getting iPod icon, was Getting the network Machine Icon
- From: Dave <email@hidden>
- Date: Fri, 23 Jan 2009 16:34:42 +0000
Hi Jean,
On 23 Jan 2009, at 13:56, Jean-Daniel Dupas wrote:
An icns file can be opened using NSImage methods.
Then choose the representation you need and convert it to JPEG as
you would do with any image.
If you want to go the "hard" way (that is not that hard):
Use ReadIconFromFSRef() to load the icns file.
Convert it into an FSRef using GetIconRefFromIconFamilyPtr().
And then draw it using PlotIconRefInContext().
Thanks for this. After looking around, I decided to do it the 'hard"
way, since I already have most of the wrapper code I can steal from
another module.
I have a question on this through. How do I fill in the parameters to
the GetIconRefFromIconFamilyPtr() call? This is my code so far:
(There may be a few typeo's in this, but it compiles ok)
CGContextRef myBitMapContextRef;
CGBitMapInfo myBitMapInfo;
CGColorSpaceRef myColorSpaceRef;
CGRect myImageRect;
size_t myImageWidth;
size_t myImageHeight;
size_t myBitsPerComponent;
size_t myNumberOfComponents;
size_t myRowBytes;
char* myImageBufferPtr;
RGBColor myLabelRGBColor:
IconFamilyHandle myIconFamilyHandle;
IconRef myIconRef;
// myFSRef is setup ok at this point
myIconFamilyHandle = NULL;
myOSErr = ReadIconFromFSRef(&myFSRef,&myIconFamilyHandle);
if (myOSErr != noErr)
goto Error;
myOSErr = GetIconRefFromIconFamilyPtr
(*myIconFamilyHandle,GetHandleSize(myIconFamilyHandle),&myIconRef);
if (myOSErr != noErr)
goto Error;
myBitMapInfo = kCGImageAlphaPremultipliedLast;
myImageWidth = 64;
myImageHeight = 64;
myBitsPerComponent = 8;
myNumberOfComponents = 4;
myRowBytes = COMPUTE_BEST_BYTES_PER_ROW(myImageWidth *
(myBitsPerComponent / 8) * myNumberOfComponents);
myImageBufferPtr = malloc(myImageHeight, myRowBytes);
myColorSpaceRef = GCColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
myBitMapContextRef = CGBitmapContextCreate
(myImageBufferPtr,myImageWidth,myImageHeight,myBitsPerComponent,myRowByt
es, myColorSpaceRef, myBitMapInfo);
CGContextClearRect(myBitMapContextRef,0,0,myWidth, myImageHeight)
myImageRect.origin.x = 0;
myImageRect.origin.y = 0;
myImageRect.size.width = myImageWidth;
myImageRect.size.height = myImageHeight;
myLabelRGBColor.red = 0;
myLabelRGBColor.green = 0;
myLabelRGBColor.blue = 0;
myOSErr = PlotIconRefInContext
(myBitMapContextRef,&myImageRect,kAlignNone,kTransformNone,
myLabelRGBColor,kPlotIconRefNormalFlags,myIconRef);
What should "myLabelRGBColor" be set to?
Also at this point, I'd like to get a pointer to the Pixel buffer in
the CGContext and return this. The code I already have will write the
JPEG file, all I need is a copy of the Pixel Data? Is there a way to
do this?
Thanks a lot
All the Best
Dave
_______________________________________________
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