I'm working with bitmap images and painting them on window components, but I have run into something I don't understand. I'm doing several image transformations back to back by using two offscreen device contexts. I alternate which is the source and desitnation DC for each transformation. My problem is that at the end of all the transformations I just get a blank DC. I've rewritten the problem to the following simplified C code representation:



HDC dc1 = CreateCompatibleDC( componentDC ),
dc2 = CreateCompatibleDC( componentDC );

SelectObject( dc1, hBitmap );
BitBlt( dc2, 0, 0, imageWidth, imageHeight, dc1, 0, 0, SRCCOPY );
BitBlt( componentDC, 0, 0, width, height, dc2, 0, 0, SRCCOPY );


I've writen the above code in MASM and at the end of the execution I get a blank component DC. I have no idea why this is happening. Does anyone know what I'm doing wrong? Any help will be apreciated.

Spara
Posted on 2004-09-14 01:46:09 by Sparafusile
Did you use LoadBitmap to get hBitmap?
Your BitBlt calls seem to be correct, you should check wether the source of the picture is right...
Posted on 2004-09-14 02:44:09 by Dom
Yes I loaded the images correctly. If I do just


HDC dc1 = CreateCompatibleDC( componentDC );
SelectObject( dc1, hBitmap );
BitBlt( componentDC, 0, 0, width, height, dc1, 0, 0, SRCCOPY );

or one transformation everything works perfectly. It's only when I start dealing with two DCs that things don't behave.

Spara
Posted on 2004-09-14 02:52:17 by Sparafusile
I'm not sure but have you tried:


HDC dc1 = CreateCompatibleDC( componentDC ),
dc2 = CreateCompatibleDC( dc1 );


Dominik
Posted on 2004-09-14 03:18:13 by Dom
You have forgotten to select a bitmap on dc2.
Currently you
BltBlt(void,dc1)
BltBlt(componentDC,void)
that's why you get nothing as a result :)
use CreateCompatibleBitmap to create a bitmap for dc2
Posted on 2004-09-14 04:49:26 by Ultrano
This is what I've tried:

SelectObject(dc1,hBitmap)
hBitmap2 = CreateCompatibleBitmap(dc1,width,height)
SelectObject(dc2,hBitmap2)
BitBlt(componentDC,dc2)

This time I get a black rectangle the size of the bitmap. How do I get the color data from the first DC into the new bitmap?

Spara
Posted on 2004-09-14 13:44:42 by Sparafusile
did you specify SRCCOPY?
Posted on 2004-09-14 14:38:21 by lifewire
I figured it out by looking at the source for donkey's Litho. The general procedure is:

SelectObject(dc1,hBitmap)
hBitmap2 = CreateCompatibleBitmap(dc1,width,height)
SelectObject(dc2,hBitmap2)
BitBlt(dc2,dc1)
BitBlt(componentDC,dc2)

I didn't know the first BitBlt was required. Thanks all.

Spara
Posted on 2004-09-14 14:47:16 by Sparafusile
I didn't know the first BitBlt was required.
The second bitmap you created for the second DC was strictly to define its size and a compatibility with the other DC. That bitmap was "empty" and selecting it into the dc2 was to establish the size of memory to be "allocated" to that DC. That DC is then ready to receive data.

That is why you have to bitblt from another DC before you can process (or copy) anything from that second DC.

Raymond
Posted on 2004-09-14 21:54:48 by Raymond