How can I take image from Rmagick object? I try image.set_data(blob), but this wrong.. Is possible make scrollable StaticBitmap?
on 2008-11-16 04:47
on 2008-11-16 07:08
You will need to convert the data over from Rmagick format to wxRuby format. You have the basic idea, in which you need to retrieve the RGB Pixel data from the RMagick object, and then apply that to a wxRuby Image object. However, you will also need to grab the Palette from RMagick, to apply to the wxRuby Image Object, through Wx::Image#set_palette(). I believe this is the method in which you need to go about this, however, I've never worked with Rmagick, and wxRuby personally. But you definately need to go through Image#set_data() and Image#set_palette to make it work. I think Alex may have a bit more experience with this, so he may be able to give you a clearer answer to this question.
on 2008-11-17 12:26
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
on 2008-11-20 23:45
Thanks you, it's work))