小编eli*_*lly的帖子

改变C#中的像素颜色

你好我正在研究读取整个图像的程序,并将绿线的颜色改为红线,例如我有这个图像 这个图片 我希望c#程序获得绿色像素并将其转换为红色我试过这段代码:`

public Bitmap ReadImgPixel(Bitmap img)
{
        Bitmap pic = new Bitmap(img,img.Width,img.Height);
        int a1 = img.Width;
        int a2 = img.Height;
        System.Drawing.Color[,] pixels = new System.Drawing.Color[a1,a2];

        for (int i = 0;i< img.Width ; i++)
        {
            for(int j=0; j < img.Height; j++)
            {

               System.Drawing.Color pxl = img.GetPixel(i, j);
                if (pxl != System.Drawing.Color.White)
                {
                    pic.SetPixel(i, j, System.Drawing.Color.Red);
                }

            }

        }
         return pic;
     }
Run Code Online (Sandbox Code Playgroud)

但结果是整个图像变成红色如何修复它!

.net c# system.drawing colors

3
推荐指数
1
解决办法
702
查看次数

标签 统计

.net ×1

c# ×1

colors ×1

system.drawing ×1