Results 1 to 11 of 11

Thread: PictureBox.SetPixel Timing

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2010
    Posts
    186

    PictureBox.SetPixel Timing

    Hi. I'm receiving through a USB connection the data for 16 image pixels at a time. The data comes in as RGB565 in two bytes per pixel for a 160 x 120 pixels image.

    If I receive the pixels data with an interval of 1 millisecond between data packets, my vb.net program works fine displaying the image. My USB device can send data a lot faster than this, so if I try to decrease the interval below 1 mS (speed up the data transfer), the display process of the image in the PictureBox starts losing data and it won't display the whole picture. This makes me think that my vb.net program is taking too long to display the image.

    How do I speed up my code? What are the lines in the code that are taking more time to process? I remember there is a way to run the code in a second thread. Is this going to help? Any ideas? Thanks.

    Code:
    For IvarImage = 0 To 15       'PROCESS DATA FOR 16 PIXELS FOR IMAGE IN PICTUREBOX. RGB565 DATA.
    
       '248 = b11111000, SHIFT 3 SPACES TO THE RIGHT.
       RedValueImage = (ALL64.Item(DevNum).Get_SquaresArray(((IvarImage * 2) + 1)) And 248) >> 3
       '7 = b00000111, SHIFT 3 SPACES TO THE LEFT. 224 = b11100000, SHIFT 5 SPACES TO THE RIGHT.
       GreenValueImage = ((ALL64.Item(DevNum).Get_SquaresArray(((IvarImage * 2) + 1)) And 7) << 3) +
          ((ALL64.Item(DevNum).Get_SquaresArray((IvarImage * 2)) And 224) >> 5)
       '31 = b00011111.
       BlueValueImage = ALL64.Item(DevNum).Get_SquaresArray((IvarImage * 2)) And 31
    
       'NEED TO SCALE UP COLOR VARIABLES.
       RedValueImage = RedValueImage * 255 / 31            '31 CORRESPONDS TO 5 BITS FOR RED
       GreenValueImage = GreenValueImage * 255 / 63        '63 CORRESPONDS TO 6 BITS FOR GRREN
       BlueValueImage = BlueValueImage * 255 / 31          '31 CORRESPONDS TO 5 BITS FOR BLUE
    
       Dim pixelColor As Color = Color.FromArgb(RedValueImage, GreenValueImage, BlueValueImage)
       bmpImage.SetPixel(xImage, yImage, pixelColor)
    
       xImage = xImage + 1         'NEXT POINT. IMAGE SIZE IS 160 X 120 PIXELS.
       If xImage > 159 Then
          xImage = 0
          yImage = yImage + 1
          If yImage > 119 Then
             yImage = 0
          End If
       End If
    
    Next
    
    ' Display the generated image in a PictureBox. 16 pixels at a time.
    pbxCameraImage.Image = bmpImage
    Last edited by VB-MCU-User; Jun 1st, 2026 at 07:16 AM.

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