[fxruby-users] FXImage + RMagick problems

Pawel Szymczykowski makenai at gmail.com
Wed Oct 19 03:21:02 EDT 2005

I posted this in ruby-talk a moment ago accidentally, so I'm sorry if you
see it twice. It's kind of late at night and I've been boggling at this
problem for a while, so my brain doesn't seem to be working right.

Here are the contents of my original ruby-talk incursion:


I'm trying to combine FXRuby with RMagick. I've searched the mail archives
(I had to index them myself! Is there an easy to use official search page
somewhere?) and apparently it's been done before, but I can't seem to get it
to work.

Basically I'm processing my image and then doing an export_pixels and trying
to convert it to the FXImage format. It works the first time, but when I try
to do it again it crashes on my saying 'invalid image' in Linux, or
something useless about abnormal termination in Windows.

This is the piece of code that seems to be giving me the specific trouble:

pixels = []
@current_image.export_pixels(0, 0, @current_image.columns,
"RGBA").each_slice(4) { |rgba| pixels << FXRGBA( *rgba ) }
an_image = FXImage.new(app, pixels, IMAGE_OWNED|IMAGE_KEEP,
@current_image.columns, @current_image.rows )

That works the first time - I get a nice picture as expected when drawn to
the canvas. The next time it happens via a timeout, I get the crash.
Actually, it's more like it works fine if I do it before calling
app.create(or maybe run?), but not afterwards.

I've also tried the following as mentioned in one of the messages in the
archives, but it complains that it's looking for an Array (buffer is
FXMemoryBuffer class of course):

buffer = FXMemoryBuffer.new( pixels )
an_image = FXImage.new(app, buffer, IMAGE_OWNED|IMAGE_KEEP,
@current_image.columns, @current_image.rows )

I've tried several different combinations of the flags, and putting
an_image.create in various places. The former didn't help at all, but in the
latter I just got a black image.

Am I doing something idiotic somewhere? I'm kind of new to ruby and GUI
development in general being more of web app guy. I can post a runnable
version of the code up somewhere if the problem isn't completely obvious and
of course if someone is feeling charitable enough to take a look at it.

Thanks for your help!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20051019/5eb736a7/attachment-0001.htm

More information about the fxruby-users mailing list