Hi Jean,

Thanks, I added the code you suggested and it basically works! I have one small problem left in that the colors are shifted, I think the routine I am returning the buffer to expects ARGB or BGRA and I am returning the opposite! Typical!

Is there an easy way to get the pixels in the reverse order or do I need to swap the bytes myself?

Thanks in Advance
All the Best
Dave


On 23 Jan 2009, at 19:27, Jean-Daniel Dupas wrote:

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 DisposeHandl

_______________________________________________

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 arch...@mail-archive.com

Reply via email to