Hey, wxMemoryDC, where did my wxBitmap go?

I’m trying to generate a wxBitmap programmatically.

I create an empty wxBitmap, use that to make a wxMemoryDC, and then paint in my wxMemoryDC. In theory, this should modify my wxBitmap, right? It doesn’t seem to. The wxMemoryDC is definitely changing, but the wxBitmap is not. Here’s the source code for a real simple example:

http://pastie.textmate.org/208902

When you run it, it copies my simple graphic to the wxFrame’s wxDC with Blit – verifying that the wxMemoryDC looks right. However, but the DrawBitmap doesn’t seem to do anything. It’s as if the wxBitmap is just transparent. Could the wxMemoryDC be making a copy of my wxBitmap? And if so, how do I get the final wxBitmap out of it?

Help!

Gre7g

One more thing… If I convert my wxBitmap to an wxImage, and then convert that BACK to a wxBitmap, it works. i.e. If I insert this before drawing my wxBitmap:

BM = wx.BitmapFromImage(BM.ConvertToImage())

Then it’s fine. So the data IS there, but it’s … grumpy? Does anyone know why this would be?

Gre7g

···

On 6/4/08, Gre7g Luterman gre7g.luterman@gmail.com wrote:

http://pastie.textmate.org/208902

I think, on Windows at least, you can’t use a wx.Bitmap while it is still selected into the wx.MemoryDC.

Ah! That would explain a lot. I never, ever would have guessed. Thanks.

try:

del MDC

before your DrawBitmap call.

Damn. It didn’t help. Well, not entirely. I’ll explain below.

Also, I know this is probably test code, but it doesn’t really make much sense to draw your bitmap inside an OnPaint call

Yeah, it’s just an example to show where I’m getting stuck. I’m not trying to do double-buffering or anything.

All I really want is to be able to create a stipple brush programmatically. Stipples can only be formed from wxBitmaps, and the only way wx creates wxBitmaps is with wxMemoryDC’s, so I don’t have a lot of options here.

I added the del MDC and that made the test program happy, but when I plug it into my stipple code, nothing changes. I’ve modified the test code to illustrate this:

http://pastie.textmate.org/209465

Instead of a brush that repeats that pattern over and over, doing a Clear() just erases the wxFrame to black. If the wxBitmap is okay, then why do you suppose my stipple isn’t being created? I guess I should have started from there in my original question, but I thought I was simplifying things.

Sorry,

Gre7g

···

On 6/4/08, Christopher Barker Chris.Barker@noaa.gov wrote: