我有一个程序可以获取图像中的每个像素并将它们输出到文本文档中。问题是它只是将它们作为数字扔在那里,而且看起来相当难看。ei " 37 37 37 36" 我希望像 GetPixel 函数一样显示它们。ei [A=255, R=4, G=255, B=131]。我目前的代码是...
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);
}
}