【问题标题】:How to filter a specific colour with AForge如何使用 AForge 过滤特定颜色
【发布时间】:2021-05-24 15:07:53
【问题描述】:

我正在使用库 AForge 并尝试将所有绿色和黄色像素更改为白色。但是红色像素应该保持不变。我尝试了一些东西,但不幸的是没有得到它。 我使用 EuclideanColorFiltering 类来过滤位图对象,但是我选择了 CenterColor 和 Radius,我没有达到我的目标。 有人可以解释一下这种过滤是如何工作的吗?

【问题讨论】:

    标签: c# colors filtering rgb aforge


    【解决方案1】:

    有getpixel和setpixel方式。 但为了快速处理,您应该使用 lockbit 并在指针中获取 Scan0

    在 lockbit 之后,您可以访问所有位图字节和颜色 例如,您可以像这样从位图中读取红色像素

        IntPtr Iptr = bitmapData.Scan0;
        for(int i = 0 ; i<frame.Height; i++)
        {
           for(int j = 0 ; j < frame.Width ; j++)
           {
             int index = ((i * frame.Width) + j) * 
                        (Bitmap.GetPixelFormatSize(frame.PixelFormat)/8);
             byte red = Marshal.ReadByte(Iptr + index + 2 ) ; 
             byte green= Marshal.ReadByte(Iptr + index +1);
             byte blue= Marshal.ReadByte(Iptr + index );
              // Also after get the colors you can Use marshal.writebyte to set the pixel your own color
             }
            }
    

    【讨论】:

      猜你喜欢
      • 2020-08-09
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      • 2022-07-15
      • 2011-03-06
      • 2015-07-15
      • 1970-01-01
      • 2020-06-27
      相关资源
      最近更新 更多