BitBlt is all black

L

Larry Serflaten

Can anyone see something wrong with the code below?


Friend Sub MapUpdate(ByRef Artwork As Bitmap, ByRef Player As MapObject)

If grxForm Is Nothing Then grxForm = Me.CreateGraphics
Dim hdcDst As IntPtr = grxForm.GetHdc

Dim art As Graphics = Graphics.FromImage(Artwork)
Dim hdcSrc As IntPtr = art.GetHdc
Dim rtn As Integer

rtn = BitBlt(hdcDst.ToInt32, 0, 46, 352, 349, hdcSrc.ToInt32, Player.Location.X - 160, Player.Location.Y - 160,
&HCC0020)
'rtn = BitBlt(hdcDst.ToInt32, 0, 0, 150, 150, hdcDst.ToInt32, 50, 50, &HCC0020)

grxForm.ReleaseHdc(hdcDst)
art.ReleaseHdc(hdcSrc)
art.Dispose()


'myArtRect.X = Player.Location.X - 160
'myArtRect.Y = Player.Location.Y - 160
'grxForm.DrawImage(Artwork, myMapRect, myArtRect, GraphicsUnit.Pixel)


The problem is that the image copied is all black. If I use the
second BitBlt line, that works to copy part of the form back on
to itself. Both calls return 1.

If I comment it all out (except the top line) and use the last 3
lines that are shown commented, that works to copy the image, but
it is just too slow. The Artwork is a much larger bitmap and I am
trying to copy only a portion of it to the form.

Can anyone see why I am getting an all black copy?

Thanks
LFS
 
C

Cor Ligthert

Larry,

I did only shortly look to it, it is not the stuff I really like.

However did you look at the question from Peter some rows above this, I
thought he had a big part of the code you need.

I always become crazy from all those different rectangles and there points
which have to be set

However when not reply, you never know, I have once made something to use as
a kind of a classic foto enlarger and I thought that that had a lot of your
question in it.

I got a start from Fergus Cooney a regular from the past for that.
(While it is as well in the resourcekit I saw later).

Cor
 
K

Ken Tucker [MVP]

Hi,

The image must be visible to get a hdc that is usable by bitblt.

Ken
--------------------
Can anyone see something wrong with the code below?


Friend Sub MapUpdate(ByRef Artwork As Bitmap, ByRef Player As MapObject)

If grxForm Is Nothing Then grxForm = Me.CreateGraphics
Dim hdcDst As IntPtr = grxForm.GetHdc

Dim art As Graphics = Graphics.FromImage(Artwork)
Dim hdcSrc As IntPtr = art.GetHdc
Dim rtn As Integer

rtn = BitBlt(hdcDst.ToInt32, 0, 46, 352, 349, hdcSrc.ToInt32,
Player.Location.X - 160, Player.Location.Y - 160,
&HCC0020)
'rtn = BitBlt(hdcDst.ToInt32, 0, 0, 150, 150, hdcDst.ToInt32, 50,
50, &HCC0020)

grxForm.ReleaseHdc(hdcDst)
art.ReleaseHdc(hdcSrc)
art.Dispose()


'myArtRect.X = Player.Location.X - 160
'myArtRect.Y = Player.Location.Y - 160
'grxForm.DrawImage(Artwork, myMapRect, myArtRect,
GraphicsUnit.Pixel)


The problem is that the image copied is all black. If I use the
second BitBlt line, that works to copy part of the form back on
to itself. Both calls return 1.

If I comment it all out (except the top line) and use the last 3
lines that are shown commented, that works to copy the image, but
it is just too slow. The Artwork is a much larger bitmap and I am
trying to copy only a portion of it to the form.

Can anyone see why I am getting an all black copy?

Thanks
LFS
 
L

Larry Serflaten

Ken Tucker said:
The image must be visible to get a hdc that is usable by bitblt.

Is that a graphics linitation? Bitblt works on a valid hDC and in
the API, the hDC can be a memory only object.

In other words, that is not how it used to work. In VB6 you can BitBlt
from a hidden picturebox.....

LFS
 
L

Larry Serflaten

Cor Ligthert said:
I did only shortly look to it, it is not the stuff I really like.

However did you look at the question from Peter some rows above this, I
thought he had a big part of the code you need.

Did you mean Subject: "There has to be an easier way"

He is not using the API. I have .NET code that works (the last 3 lines)
I want to try the API to gain speed.

LFS
 
Top