# StaticBitmap

**URL:** <https://www.ruby-forum.com/t/staticbitmap/153387>\
**Category:** wxRuby\
**Created:** [November 16, 2008, 3:47am UTC](https://www.ruby-forum.com/t/staticbitmap/153387 "2008-11-16T03:47:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3bc359/32.png) [@cyrill](https://www.ruby-forum.com/u/cyrill)\
**Post date:** [November 16, 2008, 3:47am UTC](https://www.ruby-forum.com/t/staticbitmap/153387/1 "2008-11-16T03:47:44Z")

</div>

How can I take image from Rmagick object?  
I try image.set\_data(blob), but this wrong…  
Is possible make scrollable StaticBitmap?

---

<div class="post-metadata">

**Author:** ![cyrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3bc359/32.png) [@cyrill](https://www.ruby-forum.com/u/cyrill)\
**Post date:** [November 16, 2008, 6:08am UTC](https://www.ruby-forum.com/t/staticbitmap/153387/2 "2008-11-16T06:08:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cyrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3bc359/32.png) [@cyrill](https://www.ruby-forum.com/u/cyrill)\
**Post date:** [November 17, 2008, 11:26am UTC](https://www.ruby-forum.com/t/staticbitmap/153387/3 "2008-11-17T11:26:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cyrill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3bc359/32.png) [@cyrill](https://www.ruby-forum.com/u/cyrill)\
**Post date:** [November 20, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/staticbitmap/153387/4 "2008-11-20T22:45:55Z")

</div>

Thanks you, it’s work))
