Convert a raster image to a matrix

In C #, I need to convert an image that I have already converted to Bitmap in, into a matrix of the size of the width and height of the image, which consists of uint8 bitmap data. In another word, placing the bitmap data inside the matrix and converting it to uint8, so I can perform the calculations that I intend to do in the rows and columns of the matrix.

+4
source share
1 answer

Try something like this:

public Color[][] GetBitMapColorMatrix(string bitmapFilePath) { bitmapFilePath = @"C:\9673780.jpg"; Bitmap b1 = new Bitmap(bitmapFilePath); int hight = b1.Height; int width = b1.Width; Color[][] colorMatrix = new Color[width][]; for (int i = 0; i < width; i++) { colorMatrix[i] = new Color[hight]; for (int j = 0; j < hight; j++) { colorMatrix[i][j] = b1.GetPixel(i, j); } } return colorMatrix; } 
+5
source

Source: https://habr.com/ru/post/1447331/


All Articles