I have the part to read in the file into an Integer array, although I
am not sure if this is the best way.
Dim binReader As New
IO.BinaryReader(System.IO.File.OpenRead(fileName & ".raw"))
Dim intImage(256, 256) As Integer
Dim x, y As Integer
For x = 0 To 255
For y = 0 To 255
intImage(x, y) = binReader.ReadUInt16()
Next
Next
How do I convert this array to a System.Drawing.Image or
System.Drawing.Bitmap so that I can display the image in a PictureBox?
I have a feeling I have to use a MemoryStream but am unclear about
using it.
Thanks.
Given the size of the image you're using, there's no need to use unsafe
code.
First off, you'll need to instantiate a new Bitmap image, which has the
same dimensions and pixel-depth as the source image. In this case, I'm
assuming that your image has no alpha channel, I will use a 48bpp
image:
Dim bmp As Bitmap = New Bitmap(256, 256, PixelFormat.Format48bppRgb)
Then you copy the color data for each pixel into the image using
SetPixel:
For y As Integer = 0 To 255
For x As Integer = 0 To 255
bmp.SetPixel(x, y, Color.FromArgb(...))
Next
Next
Cheers,
Mitchell Cowie