[MacRuby-devel] MacRuby 0.5 vs. CG Bitmap Context
Scott Thompson
easco at mac.com
Fri Mar 5 08:34:47 PST 2010
I'm using MacRuby to work with CoreGraphics and having some trouble with pointers.
My first attempt was to create the data for a bitmap context using NSMutableData:
bitmap_data = NSMutableData.alloc.initWithLength(image_data_size)
bitmap_context = CGBitmapContextCreate(
bitmap_data.mutableBytes(),
image_width, image_height,
8, image_width,
gray_color_space, KCGImageAlphaNone)
If I do this, I get an error that "expected instance of Pointer of type 'v', got 'C' (TypeError)"
I gather from this that CGBitmapContextCreate was expecting a (void *) and got a (UInt8 *). In C I would just type the difference away, but Ruby doesn't like ti.
I tried something like:
bitmap_data_ptr = Pointer.new_of_type('v')
bitmap_data_ptr.assign(bitmap_data.mutableBytes())
This didn't work very well either. I get an error that the system can't do a "sizeof" of an unsized type (presumably void *)
I also tried doing similar using CFDataRef (not much difference really). It looked like:
bitmap_data = CFDataCreateMutable(nil, image_data_size)
CFDataSetLength(bitmap_data, image_data_size)
bitmap_data_ptr = CFDataGetMutableBytePtr(bitmap_data)
bitmap_context = CGBitmapContextCreate(
CFDataGetMutableBytePtr(bitmap_data),
image_width, image_height,
8, image_width,
gray_color_space, KCGImageAlphaNone)
In this case, I get an error that "expected instance of Pointer, got '""' (NSMutableString) (TypeError)
Evidently MacRuby sees the return value of CFDataGetMutableBytePtr as being a string, subsequently typecasts it as such, and goes on.
Is there anything I can do to typecast the pointers to a type that MacRuby will accept?
Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100305/e4eca358/attachment.html>
More information about the MacRuby-devel
mailing list