Results 1 to 6 of 6

Thread: Grid?

  1. #1

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535

    Unhappy

    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?

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    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}

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Thumbs up

    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

  4. #4

    Thread Starter
    Fanatic Member kinjalgp's Avatar
    Join Date
    Apr 2000
    Location
    India
    Posts
    535
    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

  5. #5
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    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

  6. #6
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    Red face 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
  •  



Click Here to Expand Forum to Full Width