Private Function Int32ArrayToBitmap(ByVal pixels As Integer(), _
ByVal width As Integer, ByVal height As Integer) as bitmap
Dim bm1 As New Bitmap(width, height, Imaging.PixelFormat.Format32bppArgb)
Dim bitmapdata1 As Imaging.BitmapData
bitmapdata1 = bm1.LockBits(New Rectangle(0, 0, width, height), _
Imaging.ImageLockMode.WriteOnly, Imaging.PixelFormat.Format32bppArgb)
Dim scan0 As IntPtr = bitmapdata1.Scan0
' copy the array starting at 0 to the bitmapData, copy all pixels (wid*hei)
Runtime.InteropServices.Marshal.Copy(pixels, 0, scan0, width * height)
bm1.UnlockBits(bitmapdata1)
'bm1 now contains the image
'can save with e.g.
bm1.Save("Blah.jpg", Imaging.ImageFormat.Jpeg)
Return bm1
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Test
Dim array1(320 * 200) As Integer
Dim randomgenerator As New Random
For i As Integer = 0 To (320 * 200) - 1
Dim randColor As Integer
randColor = (255 << 24) _
Or (randomgenerator.Next(0, 256) << 16) _
Or (randomgenerator.Next(0, 256) << 8) _
Or randomgenerator.Next(0, 256)
array1(i) = randColor
Next
Me.BackgroundImage = Int32ArrayToBitmap(array1, 320, 200)
End Sub