0
votes

I must save a bitmap file, and then access the rgb of each pixel and save the decimal code of each color of pixel (meaning red, green and blue) in a separate matrix (array).

For hidding textfile in bmp lmage l need to save each rgb code in seperate matrix...lm looking for effiecient way,this is my code

This code will be run,but l cant show the result of each matrix in text of lable.how can I see the output of each matrix?

 Bitmap bmp1 = new Bitmap(@"D:a.jpg");
        pictureBox1.Image = bmp1;
        Color col = new Color();
        int w = Int32.Parse(bmp1.Width.ToString());
        int h = Int32.Parse(bmp1.Height.ToString()); 
        int[,] redstr = new int[w,h];
        int[,] greenstr = new int[w, h];
        int[,] bluestr = new int[w, h];
        int red = 0, green = 0, blue = 0;
        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < h; j++)
            {
                col = bmp1.GetPixel(i, j);
                red = col.R;
                green = col.G;
                blue = col.B;
                redstr[i, j] = red;
                greenstr[i, j] = green;
                bluestr[i, j] = blue;

            }

            }
1

1 Answers

0
votes

From the following page ... https://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx

You can use something like this to access each pixel of an image ...

private void GetPixel_Example(PaintEventArgs e)
{

// Create a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("YOURFILENAME.jpg");

// Get the color of a pixel within myBitmap.
Color pixelColor = myBitmap.GetPixel(50, 50);

}

then you can check pixelColour for your RGB components.

Evidently you will need to create a 2D array (matrix) with the same dimensions as your image. And if you need to store the separate RGB components, then you will need a 3D array.