[wxruby-users] StaticBitmap

Alex Fenton alex at pressure.to
Mon Nov 17 05:25:04 EST 2008


Cyrill Jakovlev wrote:
> How can I take image from Rmagick object?
> I try image.set_data(blob), but this wrong..
>   

set_data uses a raw, uncompressed format, but it looks like RMagick's 
to_blob method exports in known image formats.

I would use ruby's stdlib StringIO to create an in-memory representation 
that Wx::Image can read from.

require 'stringio'
str_io = StringIO( rmagick_img.to_blob ) # with whatever arguments are 
needed for to_blob
img = Wx::Image.read(str_io, Wx::BITMAP_TYPE_PNG) # or other image format

Then use Wx::Bitmap.from_image to get an object suitable for drawing on 
the screen.

> Is possible make scrollable StaticBitmap?
>   

Use Wx::ScrolledWindow to create a scrollable viewing for any contents, 
including Wx::StaticBitmap. There's different ways to use ScrolledWindow 
for which see the docs, but probably you could just use

scroll_win = Wx::ScrolledWindow.new(parent)
image = Wx::StaticBitmap.new( scroll_win, :label => bmp)
scroll_win.virtual_size = [ bmp.width, bmp.height ] # tell the window 
how big the whole canvas is
scroll_win.set_scroll_rate(5, 5) # scroll 5 pixels at a time, change as 
desired

alex




More information about the wxruby-users mailing list