# Wxruby: paint monochrome bitmaps in other colors

**URL:** <https://www.ruby-forum.com/t/wxruby-paint-monochrome-bitmaps-in-other-colors/133647>\
**Category:** Ruby\
**Created:** [April 2, 2008, 9:15am UTC](https://www.ruby-forum.com/t/wxruby-paint-monochrome-bitmaps-in-other-colors/133647 "2008-04-02T09:15:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 2, 2008, 9:15am UTC](https://www.ruby-forum.com/t/wxruby-paint-monochrome-bitmaps-in-other-colors/133647/1 "2008-04-02T09:15:47Z")

</div>

Is there an easy way to change the black and white pixels in a  
monochrome bitmap to arbitrary color values? I just want to load in a  
monochrome gif (or png) and display it in a window with, say, orange  
for the black pixels, and yellow for the white… I thought about  
swapping the palette of a loaded image file, but I can’t seem to  
actually create a Palette. But maybe this isn’t the best way.

- //

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 2, 2008, 10:16am UTC](https://www.ruby-forum.com/t/wxruby-paint-monochrome-bitmaps-in-other-colors/133647/2 "2008-04-02T10:16:11Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Is there an easy way to change the black and white pixels in a  
> monochrome bitmap to arbitrary color values? I just want to load in a  
> monochrome gif (or png) and display it in a window with, say, orange  
> for the black pixels, and yellow for the white

Set the drawing device context’s text\_foreground and text\_background to  
be the colours you want, then a mono bitmap will be drawn in those  
colours; [http://wxruby.rubyforge.org/doc/dc.html#DC\_drawbitmap](http://wxruby.rubyforge.org/doc/dc.html#DC_drawbitmap)

bitmap.depth = 1  
dc.text\_foreground = Wx::Colour.new(255, 128, 0)  
dc.text\_background = Wx::Colour.new(255, 255, 0)  
dc.draw\_bitmap(bitmap, 0, 0, false)

wxRuby specific questions are usually better posted at  
[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

alex
