如何在c#中使用欧几里德颜色过滤?我在=>中有错误filter.CenterColor = Color.FromArgb(215,30,30);

时间:2014-06-21 10:44:08

标签: c#

图像处理滤镜过滤像素,其颜色位于RGB球体的内部/外部,具有指定的中心和半径 - 它使像素保持指定球体内部/外部的颜色,并用指定的颜色填充其余部分。

using System;
using System.Collections.Generic;
using System.ComponentModel; 
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Design;
using AForge.Imaging.Filters;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    Bitmap img, img2;
    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            //Clearing previously selected image from picture box
            pictureBox1.Image = null;

            openFileDialog1.FileName = "";
            openFileDialog1.Title = "Images";

            openFileDialog1.Filter = "All Images|*.jpg; *.bmp; *.png";
            openFileDialog1.ShowDialog();
            if (openFileDialog1.FileName.ToString() != "")
            {
                pictureBox1.ImageLocation = openFileDialog1.FileName.ToString();
            }
            img = new Bitmap(openFileDialog1.FileName.ToString());
        }
        catch (Exception ex)
        {
            MessageBox.Show("Browse the image...");
        }

    }

    private void button2_Click(object sender, EventArgs e)
    {

        // create filter
        EuclideanColorFiltering filter = new EuclideanColorFiltering();
        // set center colol and radius
        filter.CenterColor = Color.FromArgb(215, 30, 30);
        filter.Radius = 100;
        // apply the filter
        filter.ApplyInPlace(img);


        pictureBox2.Image = img;
    }
}

}

// I have got error in "filter.CenterColor = Color.FromArgb(215, 30, 30);"  this line

please help me..

4 个答案:

答案 0 :(得分:0)

ARGB 颜色由4个运河定义:alpha(不透明度),红色,绿色和蓝色。

因此,您可以使用 Color.FromRgb (如果存在),或 Color.FromArgb ,第一个参数(alpha)使用255.

答案 1 :(得分:0)

你必须注意,它是Aforge库过滤器。这不是使用System.Drawing.Color中的Color,而是使用Aforge库中的RGB()。您可以使用新的RGB(颜色)简单地修复此错误。 像例子中一样:

filter.CenterColor = new RGB(Color.FromArgb(215, 30, 30));

你在AForge.Imaging类中定义了RGB()。

如果你想使用像int这样的属性来改变半径,你必须记住,filter.Radius允许从0到450只使用short(非int)。然后只使用{{1在int上它完成了。

祝你好运:)

答案 2 :(得分:0)

// create filter
EuclideanColorFiltering filter = new EuclideanColorFiltering( );
// set center colol and radius
filter.CenterColor = new RGB( 215, 30, 30 );
filter.Radius = 100;
// apply the filter
filter.ApplyInPlace( image );

答案 3 :(得分:0)

Bitmap d =new Bitmap(ofile.FileName);
for (int i = 0; i < d.Width; i++)
for (int j = 0; j < d.Height; j++)
{
                    Color C1 = d.GetPixel(i, j);
                    int r2 = C1.R;
                    int g2 = C1.G;
                    int b2 = C1.B;
                    int red = (byte)(.238 * r2 + .16 * g2 + .16 * b2);
                    r2 = red;
                    g2 = red;
                    b2 = red;
                    d.SetPixel(i, j, Color.FromArgb(r2, g2, b2));

                }