# Direct painting on bitmap

**URL:** <https://www.ruby-forum.com/t/direct-painting-on-bitmap/199664>\
**Category:** wxRuby\
**Created:** [November 26, 2010, 1:02am UTC](https://www.ruby-forum.com/t/direct-painting-on-bitmap/199664 "2010-11-26T01:02:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 26, 2010, 1:02am UTC](https://www.ruby-forum.com/t/direct-painting-on-bitmap/199664/1 "2010-11-26T01:02:00Z")

</div>

Hi, All -

I’ve been getting closer and closer to a raw painting interface (see  
‘Inserting  
RMagick RVG images in wxRuby’ for my starting point) and now what I’m  
working on (yes, I’m getting paid to work today; my kids are 3000 miles  
away  
so it’s a welcome distraction) is drawing on a MemoryDC associated with  
a  
bitmap:

```
    @picture = Bitmap.new( size_x, size_y )
    artist = MemoryDC.new
    artist.select_object @picture
    artist.set_background_mode SOLID
    artist.flood_fill( 160, 200, Colour.new( 240, 0, 0, 255 ) )

```

… and later:

```
    paint_bitmap( @picture, client_size.x, client_size.y )

```

using the definition (part of my Window sub-class):

```
def paint_bitmap bitmap, width, height
    bitmap = make_dummy if bitmap == nil # dummies for non-existant

```

images (like cpu1 if single-thread)  
rescaled\_bitmap = Bitmap.from\_image(  
bitmap.convert\_to\_image.rescale( width, height ), -1 )  
rescaled\_bitmap.save\_file( @fname, BITMAP\_TYPE\_XPM )  
paint do | renderer |  
renderer.draw\_bitmap( rescaled\_bitmap, 0, 0, false )  
end  
@sized = false  
end

What appears to be happening is that my bitmaps are not taking over from  
the  
original contents of the memory arrays, because what I see being  
rendered  
appears to be garbage pages from the screen buffer. If I change  
something in  
my GUI (like pressing a button, which changes its color to yellow), I  
see  
smears of yellow showing up in my bitmaps and getting rendered in my  
GUI.

The Bitmap#draw method referenced in the DC and MemoryDC docs appears to  
have gone bye-bye in 2.0, so I’m using the direct instantiation menthod.  
I  
finally got my copy of Smart and Hock and it says something about  
select\_object not working if the bitmap is unpopulated, so my next try  
is to  
pull up a base bitmap from a file instead of creating one from new.

Thanks in advance! 😃

---

<div class="post-metadata">

**Author:** ![walkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/96bed5/32.png) [@walkins](https://www.ruby-forum.com/u/walkins)\
**Post date:** [November 26, 2010, 1:09am UTC](https://www.ruby-forum.com/t/direct-painting-on-bitmap/199664/2 "2010-11-26T01:09:32Z")

</div>

On Thu, Nov 25, 2010 at 2:57 PM, Don W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[snip]

> using the definition (part of my Window sub-class):  
> @sized = false  
> end

[snip]

Bitmap#load\_file is also gone, but Bitmap.new has a file option. Never  
rely  
on a first-release API to be as documented. 😉

Changing make\_dummy to load a file got rid of the uninitialized bitmaps,  
but  
I still can’t paint anything on them. The above code should leave me  
with a  
screaming red bitmap, but all I get is the white from my blank.png.

---

<div class="post-metadata">

**Author:** ![walkins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/96bed5/32.png) [@walkins](https://www.ruby-forum.com/u/walkins)\
**Post date:** [November 26, 2010, 1:23am UTC](https://www.ruby-forum.com/t/direct-painting-on-bitmap/199664/3 "2010-11-26T01:23:02Z")

</div>

On Thu, Nov 25, 2010 at 3:19 PM, Don W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
[snip]

> ```
> artist.flood_fill( 160, 200, Colour.new( 240, 0, 0, 255 ) )
> 
> ```
> 
> > Never mind. I just re-read the flood\_fill docs and discovered that the  
> > Colour in the command is the BOUNDARY color, not the painting color.

You can stop laughing now, hope you enjoyed. 😃
