[wxruby-users] render natively
Alex Fenton
alex at pressure.to
Mon Sep 8 12:31:50 EDT 2008
Jim flip wrote:
> I would like to render natively i.e. via a C dll that I have wrapped
> using SWIK.
>
> So I want my c code to receive a buffer that it can render to, and then
> have WXruby display this memory buffer/bitmap.
>
A drawing context (whether an in-memory buffer, an on-screen canvas, or
a printout) is represented by a DC [1] instance in wxRuby. MemoryDC is
the specific class for in-memory buffers.
However the API and class is cross-platform and specific to WxRuby, so
you're not going to be able to pass this in directly to your dll. You
don't give a lot of info about the way your API works, but I'd think
probably the easiest way would be to have your dll render to a ruby
String in a recognised image format (wxRuby understands PNG, TIF, JPG,
BMP, TGA) then wrap this in a ruby StringIO object.
Call Wx::Image.read [2] to load this image into an object, then do
Wx::Bitmap.from_image to convert it to a windows bitmap that can be
rendered on screen. Lastly, simple draw this onto a window surface using
its paint method. Have a look at the example in samples/drawing/image.rb
to see the basics of writing an image to screen.
> Can anyone advise me what would be the best method for doing this, to
> save me having to find out the hard way.
>
This should probably work, but there's a few other options should this
not be suitable. Also have a search through the archives as there have
been a few threads about rendering images from external libraries (eg
ImageMagick).
cheers
alex
[1] http://wxruby.rubyforge.org/doc/dc.html
[2] http://wxruby.rubyforge.org/doc/image.html#Image_read
More information about the wxruby-users
mailing list