简体   繁体   中英

Converting a Bitmap image to a matrix

In C#, I need to convert an image that I have already converted to Bitmap in to a matrix of the size of the image's width and height that consists of the uint8 of the Bitmap data. In another word placing the Bitmap data inside of a matrix and converting them to uint8, so I can do the calculations that I am intended to do on the matrix rows and column.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM