Sto facendo alcuni esperimenti per trasformare array di byte in immagini. Ho trovato un certo codice e l'ho adattato per testarlo.
Creo tre array e li carico in rapida successione in una picture di nome "picmain"
Sul form c'è anche un text1 dove inserire la velocità di scambio fra le tre immagini (valore text di defaut 100) e un command1 per avviare/interrompere lo scambio di immagini.

Dopo un po' che l'ho avviato si blocca come se avessi esaurito/dimenticato di liberare qualche risorsa.
Dov'è l'inghippo?

codice:
__________________________________________________ _________
Option Explicit

Private Const BI_RGB = 0&
Private Const CBM_INIT = &H4
Private Const DIB_RGB_COLORS = 0
Private Const SRCCOPY = &HCC0020

Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO_256
bmiHeader As BITMAPINFOHEADER
bmiColors(0 To 255) As RGBQUAD
End Type


Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateDIBitmap Lib "gdi32" (ByVal hdc As Long, lpInfoHeader As BITMAPINFOHEADER, ByVal dwUsage As Long, lpInitBits As Any, lpInitInfo As BITMAPINFO_256, ByVal wUsage As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long



Dim byteBuffer0() As Byte
Dim byteBuffer1() As Byte
Dim byteBuffer2() As Byte
Dim bm_info As BITMAPINFO_256 ' DIB bitmap info.
Dim m As Integer




Private Sub ImagePrep()
Dim i As Integer

With bm_info.bmiHeader
.biSize = Len(bm_info.bmiHeader)
.biWidth = 640 ' Width in pixels.
.biHeight = -512 ' Height in pixels. (invert to start at 0,0)
.biPlanes = 1 ' 1 color plane.
.biBitCount = 8 ' 8 bits per pixel.
.biCompression = BI_RGB ' No compression.
.biSizeImage = 0 ' Unneeded with no compression.
.biXPelsPerMeter = 0 ' Unneeded.
.biYPelsPerMeter = 0 ' Unneeded.
.biClrUsed = 256 ' # colors in color table that are used by the image. 0 means all.
.biClrImportant = 256 ' # important colors. 0 means all.
End With

For i = 0 To 255
bm_info.bmiColors(i).rgbRed = i
bm_info.bmiColors(i).rgbGreen = i
bm_info.bmiColors(i).rgbBlue = i

bm_info.bmiColors(i).rgbReserved = 0
Next i
End Sub


Private Function paintImage(n As Integer) As Long
Dim screen_hdc As Long
Dim compat_dc As Long
Dim hdib As Long

screen_hdc = GetDC(0) 'get screen's device context
If n = 0 Then hdib = CreateDIBitmap(screen_hdc, bm_info.bmiHeader, CBM_INIT, byteBuffer0(0), bm_info, DIB_RGB_COLORS)
If n = 1 Then hdib = CreateDIBitmap(screen_hdc, bm_info.bmiHeader, CBM_INIT, byteBuffer1(0), bm_info, DIB_RGB_COLORS)
If n = 2 Then hdib = CreateDIBitmap(screen_hdc, bm_info.bmiHeader, CBM_INIT, byteBuffer2(0), bm_info, DIB_RGB_COLORS)

compat_dc = CreateCompatibleDC(hdc) 'create a compatible device context.
SelectObject compat_dc, hdib 'select the DIB into the compatible DC.
BitBlt picmain.hdc, 0, 0, 640, 612, compat_dc, 0, 0, SRCCOPY ' draw image
DeleteDC compat_dc 'destroy the DC
DeleteDC hdib
picmain.Refresh
End Function



Private Sub Command1_Click()
If Timer1.Enabled Then
Timer1.Enabled = False
Else
Timer1.Interval = Val(Text1.Text)
Timer1.Enabled = True
End If
End Sub

Private Sub Form_Load()
Dim i As Long, n As Integer
Dim imgSize As Long


imgSize = 391680
Show
DoEvents


ImagePrep

ReDim byteBuffer0(0 To imgSize)
ReDim byteBuffer1(0 To imgSize)
ReDim byteBuffer2(0 To imgSize)

n = 0



'fill up a pattern to daw

For i = 0 To imgSize
byteBuffer0(i) = n
If i Mod 8 = 0 Then n = n + 1
If n >= 255 Then n = 0
Next i

For i = 0 To imgSize
byteBuffer1(i) = n
If i Mod 8 = 0 Then n = n + 5
If n >= 255 Then n = 0
Next i

For i = 0 To imgSize
byteBuffer2(i) = n
If i Mod 8 = 0 Then n = n + 10
If n >= 255 Then n = 0
Next i

m = 0


End Sub

Private Sub Timer1_Timer()

m = m + 1
If m = 3 Then m = 0
paintImage (m)
End Sub