0
点赞
收藏
分享

微信扫一扫

c#读取图片成rgb二维数组


​​


​​

全栈工程师开发手册 (作者:栾鹏)

​​ c#教程全解​​

c#读取图片成rgb二维数组,输入图片文件地址,输出颜色二维数组

测试代码

static void Main()
{
Color[,] allcolor=img2color("11.jpg");
for (int i=0;i<allcolor.GetLength(0);i++) {

for (int j=0;j<allcolor.GetLength(1);j++) {
System.Console.WriteLine(allcolor[i, j]);
}
}
}

实现代码

public static Color[,] img2color(String imgfile)
{
Bitmap img = new Bitmap(imgfile);
Color[,] allcolor = new Color[img.Height, img.Width];
for (int h = 0; h < img.Height; h++)
for (int w = 0; w < img.Width; w++)
{
allcolor[h, w] = img.GetPixel(w, h);
}
GC.Collect();
return allcolor;
}


举报

相关推荐

0 条评论