|
-
Nov 14th, 2002, 05:45 PM
#1
Thread Starter
Hyperactive Member
Getting pixel colors with DCs
Hello guys,
that's my code:
Code:
dim DCSprite as long
dim BMPSprite as long
Public Function SetPicture(hDC As Long, lWidth As Long, lHeight As Long) As Boolean
DCSprite = CreateCompatibleDC(0)
BMPSprite = CreateCompatibleBitmap(hDC, lWidth, lHeight)
If (DCSprite < 1) Or (BMPSprite < 1) Then
SetPicture = False
Exit Function
End If
SelectObject DCSprite, BMPSprite
BitBlt DCSprite, 0, 0, lWidth, lHeight, hDC, 0, 0, vbSrcCopy
SetPicture = True
End Function
All works fine, if I bitblt to form1 I can get my image, but if I try to get the color of pixels with GetPixel it returns always -1...
Any suggestions??!?
Thx,
Xmas
-
Nov 14th, 2002, 07:37 PM
#2
Addicted Member
on wich dc do you use the getpixel? I've tried the following with your code:
VB Code:
Public Function SetPicture(hdc As Long, lWidth As Long, lHeight As Long) As Boolean
DCSprite = CreateCompatibleDC(0)
BMPSprite = CreateCompatibleBitmap(hdc, lWidth, lHeight)
If (DCSprite < 1) Or (BMPSprite < 1) Then
SetPicture = False
Exit Function
End If
SelectObject DCSprite, BMPSprite
BitBlt DCSprite, 0, 0, lWidth, lHeight, hdc, 0, 0, vbSrcCopy
SetPicture = True
MsgBox GetPixel(DCSprite, 2, 0)
BitBlt Picture2.hdc, 0, 0, lWidth, lHeight, DCSprite, 0, 0, vbSrcCopy
Picture2.Refresh
MsgBox GetPixel(Picture2.hdc, 2, 0)
End Function
and the getpixel work both times.
can you post a bigger part of code or your project, maybe i'll have a better chance to see what you are doing wrong.
- Valkan
'You keep creatures in cages and release them to fight? That's sick!'
-
Nov 15th, 2002, 03:42 AM
#3
Thread Starter
Hyperactive Member
Oh well, Tonight I was "arrabbiato" so I changed all my code and I decided to do it with picture1.point, and setpixel... I used picture1.point (that is the slowest) because getpixel always returns -1!!!!
I used my previous code,for a picturebox, for a form... Nothing... Picture1.autoredraw and form1.autoredraw were true they were visible, all seemed to be correct but gepixel returned -1. I can't understand why... Before i post I tried to see if getpixel worked, stopping my program and in the writing in the immediate window:
Code:
print getpixel(form1.hdc,2,0) <---- Sure here I'm in boundaries...
returned -1... Something wrong in my computer yesterday night ??!?
I looked at this forum for other posts and I found that people had my problem and they resolved it, They had not set autoredraw property to true, but in my project they were right!!! 
Does getpixel works with picture1.visible=false? in my computer no. It doesn't work neither with picture1.visible=true...
I'm unhappy...
Thx Xmas.
-
Nov 15th, 2002, 08:08 AM
#4
Thread Starter
Hyperactive Member
I started a new project, put on form1 two pictureboxes, one command button and the below code:
Code:
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, _
ByVal dwRop As Long) As Long
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As Long
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, _
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, _
ByVal x As String, ByVal y As Long) As Long
Public Function SetPicture(hdc As Long, lWidth As Long, lHeight As Long) As Boolean
Dim dcsprite As Long
Dim bmpsprite As Long
dcsprite = CreateCompatibleDC(0)
bmpsprite = CreateCompatibleBitmap(hdc, lWidth, lHeight)
If (dcsprite < 1) Or (bmpsprite < 1) Then
SetPicture = False
Exit Function
End If
SelectObject dcsprite, bmpsprite
BitBlt dcsprite, 0, 0, lWidth, lHeight, hdc, 0, 0, vbSrcCopy
SetPicture = True
MsgBox GetPixel(dcsprite, 2, 0)
BitBlt Picture2.hdc, 0, 0, lWidth, lHeight, dcsprite, 0, 0, vbSrcCopy
Picture2.Refresh
MsgBox GetPixel(Picture2.hdc, 2, 0)
End Function
Private Sub Command1_Click()
Call SetPicture(Picture1.hdc, Picture1.ScaleWidth, Picture1.ScaleHeight)
End Sub
I think this is what you've done.
Two Msgboxes appear, both of them give me -1.
Scalemode properties of form, picture1 and picture2 are set to Pixel. They have also autoredraw property set to true.
Xmas.
-
Nov 15th, 2002, 08:42 AM
#5
Addicted Member
Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, _
ByVal x As String, ByVal y As Long) As Long
should be: Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, _
ByVal x As long, ByVal y As Long) As Long
now it will work
- valkan
'You keep creatures in cages and release them to fight? That's sick!'
-
Nov 15th, 2002, 09:26 AM
#6
Thread Starter
Hyperactive Member
uhm...
AAAAAAAAAAAAAAAAAAAAHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!
Thx Valkan, I copied that declaration, but I didn't looked at it... I was sure of it...
-
Nov 15th, 2002, 09:37 AM
#7
Addicted Member
nah, don't worry, stuff like this happens to everyone once in a while (and that of course include me)... you've got an error, look closely at all the more complicated part of your code because you are sure that the error is got to be there... only to find out after what can be a long while that the error was caused by the simplest of mistake. Welcome to the club budy
'You keep creatures in cages and release them to fight? That's sick!'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|