Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use of bitblt 2

Status
Not open for further replies.

murrayja

Programmer
May 6, 2000
90
US
I have a control in which a TIFF file is displayed with dithering, ie not just black and white but shades of grey.

I want to copy the control screen data into a memory device context and work with the pixels there.

The code I have seems to copy only black(0) and white(HFFFFFF)
into the memory DC. When I run the code I get no stops on colors between black and white but when I use getpixel on the control I get shades of grey as well.

I am sure that I am doing something dumb with the API but I don't know what.

dim chdc as long, cbmp as long, x as long, y as long
Const SRCCOPY = &HCC0020

cHdc = CreateCompatibleDC(ctl.hdc)
cBmp = CreateCompatibleBitmap(cHdc, _
ctl.width, ctl.height)
rc = SelectObject(cHdc, cBmp)
rc = BitBlt(cHdc, 0, 0, ctl.width, ctl.height, _
ImgX.hdc, 0, 0, SRCCOPY)
For x = 0 To ctl.width
For y = 0 To ctl.height / 4
c = GetPixel(cHdc, x, y)
If (c = -1) Then
c = c ' never stops
End If
If (c <> &HFFFFFF) And (c <> 0) Then
c = c ' never stops
End If
Next
Next
End If
Next
DeleteDC (cHdc)
DeleteObject (cBmp)
 
Try changing
Code:
cBmp = CreateCompatibleBitmap(cHdc, _
                       ctl.width, ctl.height)
to
Code:
cBmp = CreateCompatibleBitmap([b]ctl.hdc[/b], _
                       ctl.width, ctl.height)

 
No joy. I still copy no grey shades.
I think its the bitblt but I have stared at it till I can't see it.
 
I think (like you) that the problem is in BitBlt.

BltBlt requires handles to 2 DC's, not a handle to a control such as ImgX.hdc.

Have you looked at "rc" after the BitBlt call.

I found the following on MSDN:

To store an image temporarily, your application must call CreateCompatibleDC to create a DC that is compatible with the current window DC. After you create a compatible DC, you create a bitmap with the appropriate dimensions by calling the CreateCompatibleBitmap function and then select it into this device context by calling the SelectObject function.

After the compatible device context is created and the appropriate bitmap has been selected into it, you can capture the image. The BitBlt function captures images. This function performs a bit block transfer that is, it copies data from a source bitmap into a destination bitmap. However, the two arguments to this function are not bitmap handles. Instead, BitBlt receives handles that identify two device contexts and copies the bitmap data from a bitmap selected into the source DC into a bitmap selected into the target DC. In this case, the target DC is the compatible DC, so when BitBlt completes the transfer, the image has been stored in memory. To redisplay the image, call BitBlt a second time, specifying the compatible DC as the source DC and a window (or printer) DC as the target DC.



&quot;Life is full of learning, and then there is wisdom&quot;
 
imgx has a devivice context. it is a control that displays tif images.
rc is true (<>0)after bitblt.

If I 'turn it around after the first bitblt like
rc = BitBlt(cHdc, 0, 0, 200, 12, _
ImgX.hdc, 0, 0, SRCCOPY)

rc = BitBlt(ImgX.hdc, 0, 100, 200, 12, _
chdc, 0, 0, SRCCOPY)

I get a black rectangle displaced vertically by 50 pixels from the text I thought I was 'bitblt'ng so my compatible bitmap is getting set to black.
 
I have found that if you set the AutoRedraw property of both the source and destination images to TRUE before the BitBlt and the to FALSE afterwards - then it worked.

Also have you got the ScaleMode set to VbPixels?

&quot;Life is full of learning, and then there is wisdom&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top