Bitmap myBitmap = new Bitmap("Grapes.jpg"); for (int i = 0; i < myBitmap.Width; i++) for (int j = 0; j < myBitmap.Height; j++) { Color pixelColor = myBitmap.GetPixel(i, j); byte g = pixelColor.G; byte b = pixelColor.B; byte r = pixelColor.R; }
转换成string出来。 public void image2Ary(ref Bitmap bitIn, //源图 Boolean ifFromAuto, //是否是由代码生成的图 int iStr, int jStr, int iEnd, int jEnd, //指定图像中需转换的矩形区域 out int[, ,] aOut)//返回的3D数组 //使用非指针的方法将位图中的指定矩形部分转换成数组, { int xBod = bitIn.Width, yBod = bitIn.Height; MemoryStream ms = new MemoryStream(); byte[] bytImg; System.Drawing.Image imageIn = bitIn;imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); bytImg = ms.ToArray();int i, j, k, xTmp = 54; int[, ,] ATmp = new int[xBod, yBod, 4]; 这是个代码片段。具体实现还是挺简单的。
Bitmap.LockBit
BitmapData.Stride
BitmapData.Scan0
...
for (int i = 0; i < myBitmap.Width; i++)
for (int j = 0; j < myBitmap.Height; j++)
{
Color pixelColor = myBitmap.GetPixel(i, j);
byte g = pixelColor.G;
byte b = pixelColor.B;
byte r = pixelColor.R;
}
public void image2Ary(ref Bitmap bitIn, //源图
Boolean ifFromAuto, //是否是由代码生成的图
int iStr, int jStr, int iEnd, int jEnd, //指定图像中需转换的矩形区域
out int[, ,] aOut)//返回的3D数组
//使用非指针的方法将位图中的指定矩形部分转换成数组,
{
int xBod = bitIn.Width,
yBod = bitIn.Height;
MemoryStream ms = new MemoryStream();
byte[] bytImg;
System.Drawing.Image imageIn = bitIn;imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
bytImg = ms.ToArray();int i, j, k, xTmp = 54;
int[, ,] ATmp = new int[xBod, yBod, 4]; 这是个代码片段。具体实现还是挺简单的。