• 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 iPod icon, was Getting the network Machine Icon
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting iPod icon, was Getting the network Machine Icon


  • Subject: Re: Getting iPod icon, was Getting the network Machine Icon
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Fri, 23 Jan 2009 18:33:12 +0100


Le 23 janv. 09 à 17:34, Dave a écrit :

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)



myIconFamilyHandle = NULL;
myOSErr = ReadIconFromFSRef(&myFSRef,&myIconFamilyHandle);
if (myOSErr != noErr)
	goto Error;

myOSErr = GetIconRefFromIconFamilyPtr (*myIconFamilyHandle,GetHandleSize(myIconFamilyHandle),&myIconRef);
if (myOSErr != noErr)
goto Error;

look fine to me.

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,myRowBytes, 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?

I think you can pass NULL for the label color.



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?

myImageBufferPtr is the pixel buffer.

To create the image, you can also use an NSImage,

NSImage *img = [[NSImage alloc] initWithSize:NSMakeSize(myImageWidth, myImageHeight)];
[img lockFocus]
CGContextRef ctxt = [[NSGraphicsContext currentContext] graphicPort];


// draw

[img unlockFocus]

And now, use NSImage function to save it as a JPEG. It's easier than dealing with all the bitmap stuff.

An other way may be to use CGBitmapContextCreateImage() to create a CGImageRef from your context, and then use ImageIO (CGImageDestinationRef) to export your image.







_______________________________________________

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 iPod icon, was Getting the network Machine Icon
      • From: Dave <email@hidden>
References: 
 >Getting the network Machine Icon (From: Sandro Noel <email@hidden>)
 >Getting iPod icon, was Getting the network Machine Icon (From: Dave <email@hidden>)
 >Re: Getting iPod icon, was Getting the network Machine Icon (From: Russell Hancox <email@hidden>)
 >Re: Getting iPod icon, was Getting the network Machine Icon (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Getting iPod icon, was Getting the network Machine Icon (From: "email@hidden" <email@hidden>)
 >Re: Getting iPod icon, was Getting the network Machine Icon (From: Dave <email@hidden>)
 >Re: Getting iPod icon, was Getting the network Machine Icon (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Getting iPod icon, was Getting the network Machine Icon (From: Dave <email@hidden>)

  • Prev by Date: sqlite iphone question....
  • Next by Date: Re: Encryption: Simplest method to encrypt a SQLite DB file...? {iPhone}
  • Previous by thread: Re: Getting iPod icon, was Getting the network Machine Icon
  • Next by thread: Re: Getting iPod icon, was Getting the network Machine Icon
  • Index(es):
    • Date
    • Thread