Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a Bitmap image to a matrix

Tags:

c#

bitmap

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.

like image 703
Payam Avatar asked Nov 20 '12 20:11

Payam


People also ask

Can object be converted into bitmap?

Converting a vector graphic or object to a bitmap lets you apply special effects to the object with CorelDRAW. The process of converting a vector graphic to a bitmap is also known as “rasterizing.” When you convert the vector graphic, you can select the color mode of the bitmap.

How do I convert JPG to bitmap?

This wikiHow will teach you how to convert JPG to Bitmap, which is more commonly referred to as .bmp. You can use MS Paint for Windows computers, Mac's Preview, and Zamzar Online on both your computer's or mobile's web browser. Open Paint. You'll find this application in the Start menu listed under "P" in the alphabetical listing. Press Ctrl + O.

How do I create a bitmap image in paint?

1. Open Paint (Windows) or Preview (Mac). 2. Press Ctrl + O (Windows) or Cmd + O (Mac). 3. Click File > Save as (Windows) or File > Export (Mac). 4. Select Bitmap/Microsoft Bitmap from the drop-downs next to "Save as type" (Windows) or "Format" (Mac). 5. Click Save.

What is BMP (bitmap file)?

The Microsoft Windows bitmap (BMP) format is widely known and has been around for decades. BMP (bitmap image file, device independent bitmap file format, bitmap) files are raster images used for the storage of bitmap digital images separate from the display device.

Can it convert color files to bitmap files?

It can not convert Color to Bitmap format. in that case show the parts of your code, where you create the grayscale bitmap. And I'd still suggest to checkout Bitmap.Lockbits, because its not only faster, but also gives you byte (as you stated in your question) and not color


1 Answers

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;
}
like image 51
Rahul Tripathi Avatar answered Oct 01 '22 11:10

Rahul Tripathi