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: Jean-Daniel Dupas <email@hidden>
- Date: Fri, 23 Jan 2009 20:27:46 +0100
Le 23 janv. 09 à 19:53, Dave a écrit :
Hi Jean,
Thank you so much for your help. I've almost got the code in place
now. But please see below.
On 23 Jan 2009, at 17:33, Jean-Daniel Dupas wrote:
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.
The requirement of the function I am writing has now changed because
I found a different way of doing it that requires much less changes
to the rest of the application. Basically there is a framework of
sorts that calls my function (GetIconImage), all I have to do is to
render the Icon into a BitMap/PixMap and then return a pointer to it
from my function, e.g. the function that calls my function need to
return a buffer that is width * height * 4 in size that contains the
pixels and everything else will be taken care of!
So, I if change the bit that computes the Row Bytes value so it is
(width * 4) and change the malloc to malloc(width * height * 4) then
just return myImageBufferPtr, this should be ok?
Yes. You should release the CGContext too. If you provide a buffer
when you create it (this is what you do), your are responsible to free
it, and so, releasing the bitmap context will not affect it.
Also, how to I free the memory allocated by myBitMapContextRef,
myIconRef and myIconFamily Icon? I can't seem to find dispose/
release functions for these objects.
All CG type are CoreFoundation objects. So you can use CFRelease to
free the bitmap context. There is also a CGContextRelease function but
the doc says that this function is equivalent to CFRelease, except
that it does not cause an error if the context parameter is NULL.
For the IconRef, the function is ReleaseIconRef().
And the icon family is an handle, and should be freed using
DisposeHandle().
Thanks again, you have been a great help!
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
_______________________________________________
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