I have a program which gets every pixel in an image and outputs them into a text document. The problem is that it just throws them in there are as numbers and it looks rather ugly. e.i. " 37 37 37 36" I wish to display them much like the GetPixel function does. e.i. [A=255, R=4, G=255, B=131]. My current code is...
Bitmap bmp = new Bitmap("Space big.jpg");
Rectangle bmpRec = new Rectangle(0, 0, bmp.Width, bmp.Height); //Creates Rectangle for holding picture
BitmapData bmpData = bmp.LockBits(bmpRec, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); //Gets the Bitmap data
IntPtr Pointer = bmpData.Scan0; //Sets pointer
int DataBytes = Math.Abs(bmpData.Stride) * bmp.Height; //Gets array size
byte[] rgbValues = new byte[DataBytes]; //Creates array
Marshal.Copy(Pointer, rgbValues, 0, DataBytes); //Copies of out memory
bmp.UnlockBits(bmpData);
StringBuilder Pix = new StringBuilder(" ");
Stopwatch Timer = new Stopwatch();
pictureBox1.Image = bmp;
StringBuilder EachPixel = new StringBuilder("");
Timer.Start();
for (int i = 0; i < bmpData.Width; i++)
{
for (int j = 0; j < bmpData.Height; j++)
{
// compute the proper offset into the array for these co-ords
var pixel = rgbValues[i + j * Math.Abs(bmpData.Stride)];
Pix.Append(" ");
Pix.Append(pixel);
}
}