I need code to read an image from a file and convert the image into an array of integers. The format of image is BMP
and I\'m using vb.net-2010
You can find a similar question and valuable answers (although the question and answers are for c# i think they will help you to understand the solution) at : How can I read image pixels' values as RGB into 2d array?
First you need to load the file to a System.Drawing.Bitmap object. Then you can read pixel values using GetPixel method. Note that every pixel data includes a Color value. You can convert this value to an integer value using ToArgb() method.
Imports System.Drawing;
...
Dim img As New Bitmap("C:\test.JPG")
Dim imageArray (img.Width, img.Height) As Integer
Dim i, j As Integer
For i = 0 To img.Width
For j = 0 To img.Height
Dim pixel As Color = img.GetPixel(i,j)
imageArray (i,j) = pixel.ToArgb()
Next j
Next i
...
and the case storing a 2D array to a BMP object(Assuming you have a 100x100 2D array imageArray)
Imports System.Drawing;
...
Dim img As New Bitmap(100,100)
Dim i, j As Integer
For i = 0 To img.Width
For j = 0 To img.Height
img.SetPixel(i,j,Color.FromArgb(imageArray(i,j)))
Next j
Next i
...