|
-
Nov 2nd, 2002, 02:25 PM
#1
Thread Starter
Junior Member
SetPixel Problem
Hi,
I have used the SetPixel API to fill the screen with lines, i know i could use the MoveToEx, and LineTo api's but i need to set each pixel.
When it gets to about the 7th line the program crashes.
Here is the code i put in a module...
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Sub Main()
For a = 1 To 1024 Step 10
For b = 1 To 768
SetPixel GetWindowDC(0), a, b, RGB(255, 0, 200)
DoEvents
Next b
SetPixel GetWindowDC(0), a, b, RGB(255, 0, 200)
DoEvents
Next a
End Sub
It also goes extremely slow!!!
-
Nov 2nd, 2002, 02:35 PM
#2
Good Ol' Platypus
SetPixel is extremely slow by nature. Do a search, there are routines that are (a bit) faster.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Nov 2nd, 2002, 02:38 PM
#3
Thread Starter
Junior Member
Could you name some please.
I believe in Death after Life!
-
Nov 2nd, 2002, 03:00 PM
#4
Ex-Super Mod'rater
First can I point out that in the code you gave you used:
VB Code:
GetWindowDC(0)
'Shouldnt you use this:
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
GetWindowDC(GetDesktopWindow)
Anyway theres a neat way of getting a pointer that points to the place in memory the picture is stored and editing it that way, see these two threads for more about it:
http://www.vbforums.com/showthread.p...hreadid=210508
http://www.vbforums.com/showthread.p...hreadid=210500
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Nov 2nd, 2002, 03:10 PM
#5
Thread Starter
Junior Member
I didnt really understand those.
i dont know about the GetWindowDC thing but it seems to work fine.
I believe in Death after Life!
-
Nov 2nd, 2002, 03:19 PM
#6
Junior Member
If you want alternatives to SetPixel look at this thread:
http://www.vbforums.com/showthread.p...hreadid=209455
ISDP
"Mmm, so I hear they have the internet on computers these days..."
-
Nov 2nd, 2002, 06:33 PM
#7
Frenzied Member
Your variables might be being declared oddly by VB. Try declaring them explicitly before using them.
Also, NEVER EVER EVER use GetWindowDC(0) in EVERY call to SetPixel or GetPixel. It will slow your program down so very much.
Z.
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
|