|
-
Apr 25th, 2000, 11:35 AM
#1
Thread Starter
Fanatic Member
I am using Pset to draw grid on my picture box every time my App. loads. But this take a lot of time to execute. Can anyone suggest me an alternate method of drawing grid on picture box?
-
Apr 25th, 2000, 01:16 PM
#2
Fanatic Member
Use the SetPixel API call rather than the PSet function and you will see a significant increase in speed, the declare goes like this:
Code:
Declare Function SetPixel Lib "gdi32" Alias "SetPixel" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
and implement it something like this:
Code:
Private Sub Form_Paint()
dim x as Integer, y as Integer, color as Long
dim returnvalue as Long
x = 15 ' 15th pixel across
y = 15 ' 15th pixel down
color = RGB(0, 0, 255) ' blue
returnvalue = SetPixel(x, y, color) ' color pixel at x=15 y=15 the color blue
End Sub
Good Luck 
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Apr 25th, 2000, 02:48 PM
#3
Fanatic Member
Even Quicker !!!
Use API SetBitmapBits.
You can dump graphics straight out of a byte array...
I used it for a graphics program when the setpixel API was still too slow
Even, getbitmapbits, modify the array then setbitmap bits really flies
-
Apr 25th, 2000, 08:22 PM
#4
Thread Starter
Fanatic Member
Hello YoungBuck.
I tried your code but It shows an error "Argument Not Optional". Itried to find out where the error was but could not get it. Please give me the proper code.
Thanks a lot.
Kinjal
-
Apr 25th, 2000, 08:44 PM
#5
Hyperactive Member
Hi.
Code:
Private Declare Function SetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub Form_Paint()
Dim winrect As RECT ' rectangle of window Form1
Dim rgbval As Long ' RGB value of the randomly selected color
Dim x As Long, y As Long ' counters for x and y coordinates
Dim retval As Long ' return value
' Get the rectangle of window Form1.
retval = GetWindowRect(Form1.hwnd, winrect)
' Loop through each pixel within Form1.
For y = 0 To winrect.Bottom - winrect.Top Step 15
For x = 0 To winrect.Right - winrect.Left Step 15
rgbval = RGB(0, 0, 255)
' Set the pixel to the color above.
retval = SetPixel(Form1.hdc, x, y, rgbval)
Next x
Next y
End Sub
-
Apr 26th, 2000, 01:49 AM
#6
Fanatic Member
DUH!
Sorry Kinjal replace
Code:
returnvalue = SetPixel(x, y, color)
with this
Code:
returnvalue = SetPixel(Form1.hdc, x, y, color)
sorry for the typo, also if you are going to be drawing to a picturebox you may want to use the Picturebox's paint event (Picture1_Paint) and the Picturebox's handle (Picture1.hdc).
Sorry :P
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
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
|