Click to See Complete Forum and Search --> : Pixel array -----> Picturebox (wow, pset is slow)
icematrix
Feb 4th, 2001, 10:53 PM
What is the most compact and simple way to take a 50x50 array of color values and blit that into a 50x50 picturebox. Sorry if you've heard this one before.
- // /\/\atrix // -
YoungBuck
Feb 4th, 2001, 11:24 PM
The SetPixelV would probably be the fastest way to draw directly to the picturebox. If this isn't fast enough you can draw directly to an offscreen DC and then just blt it directly from memory into the picture box (alot more code), let me know if you need an example for that....
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 Sub Form_Load()
Dim iX As Integer
Dim iY As Integer
Dim lColorArray(0 To 50, 0 To 50)
' resize picture box to 50 X 50 pixels
Picture1.Height = 50 * Screen.TwipsPerPixelX
Picture1.Width = 50 * Screen.TwipsPerPixelY
Picture1.AutoRedraw = True
' fill the array with random colors
For iX = 0 To 50
For iY = 0 To 50
lColorArray(iX, iY) = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Next iY
Next iX
' set the pixel's color
For iX = 0 To 50
For iY = 0 To 50
SetPixelV Picture1.hdc, iX, iY, lColorArray(iX, iY)
Next iY
Next iX
End Sub
icematrix
Feb 4th, 2001, 11:45 PM
Thank you! That worked wonderfully.
Sastraxi
Feb 5th, 2001, 07:11 PM
However, YoungBuck, I would code for that...
So far i'm getting a frame every 9 secs for a 640x480 picture w/ get & setpixelV
(but i'll be using DDraw soon)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.