|
-
Feb 27th, 2001, 01:48 PM
#1
Just a quick question. Can you use GetPixel with an offscreen DC?
-
Feb 27th, 2001, 02:19 PM
#2
Fanatic Member
-
Feb 27th, 2001, 04:46 PM
#3
Well, ive found that it will return -1 if i use a hidden picture box. I'm wondering if it will work if i use an offscreen DC
-
Feb 27th, 2001, 05:18 PM
#4
PowerPoster
It will.
If you want to use a picturebox set autoredraw to true..
-
Feb 27th, 2001, 07:18 PM
#5
transcendental analytic
Same problem appears for any DC if there's no bitmap selected.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Feb 28th, 2001, 12:07 PM
#6
Retired VBF Adm1nistrator
Zaei, just create a DC in memory.
I do it in the source code I released/posted in the misc.bas module.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 28th, 2001, 01:17 PM
#7
Ok, from my experiments, you CANNOT use GetPixel
with an offscreen DC. You can Blt from one, which I
tested, but using GetPixel returns 0 (and when the pixel
referenced is invalid, it returns -1).
-
Feb 28th, 2001, 02:39 PM
#8
Fanatic Member
I made a memory DC and did a BitBlt of the desktop to it.
Using a For..Next loop with GetPixel() resulted in the colours and not 0 or -1!
-
Feb 28th, 2001, 02:47 PM
#9
Hrmmm.. Post code, please?
-
Mar 2nd, 2001, 03:27 PM
#10
Fanatic Member
Well, here it is my friend:
Code:
Option Explicit
'This project needs 1 picturebox
Private 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
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Dim W As Long
Dim H As Long
Dim memDC As Long
Dim memBMP As Long
Private Sub Form_Activate()
Me.Refresh
BitBlt Me.hdc, 0, 0, W, H, memDC, 0, 0, vbSrcCopy
End Sub
Private Sub Form_DblClick()
Unload Me
End Sub
Private Sub Form_Load()
W = Screen.Width
H = Screen.Height
Picture1.ScaleMode = vbPixels
Picture1.BackColor = 0
Me.ScaleMode = vbPixels
Me.Move 0, 0, W, H
W = W / Screen.TwipsPerPixelX
H = H / Screen.TwipsPerPixelY
Picture1.Move W - Picture1.Width, H - Picture1.Height
memDC = CreateCompatibleDC(Me.hdc)
memBMP = CreateCompatibleBitmap(Me.hdc, W, H)
SelectObject memDC, memBMP
BitBlt memDC, 0, 0, W, H, GetDC(0), 0, 0, vbSrcCopy 'Capture desktop...
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim C As Long
Dim i As Integer
Static BUSY As Boolean
If (BUSY) Then Exit Sub
BUSY = True
If (x < Picture1.Width) And (y < Picture1.Height) Then
For i = 0 To 9
'Get the colour in MEMORY!!! not from the Form!!!
C = GetPixel(memDC, x + i, y)
SetPixelV Picture1.hdc, x + i, y, C
C = GetPixel(memDC, x + i, y + 1)
SetPixelV Picture1.hdc, x + i, y + 1, C
Next i
End If
BUSY = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
DeleteDC memDC
DeleteObject memBMP
Set Form1 = Nothing
End
End Sub
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
|