将CMYK转换为RGB c#

时间:2018-01-30 06:29:03

标签: c# asp.net

我尝试使用c#将CMYK颜色模式转换为RGB模式。

我已经尝试过RasterEdge.DocImageSDK库,但在构建项目时会给我错误。

我有图像的物理路径。

 System.Drawing.Image OrjinalResim = System.Drawing.Image.FromFile(orj_resim_adi.FullName);
                ResimIslem ri = new ResimIslem(OrjinalResim);

1 个答案:

答案 0 :(得分:0)

试试吧

    public struct CMYK
{
    private double _c;
    private double _m;
    private double _y;
    private double _k;

    public CMYK(double c, double m, double y, double k)
    {
        this._c = c;
        this._m = m;
        this._y = y;
        this._k = k;
    }

    public double C
    {
        get { return this._c; }
        set { this._c = value; }
    }

    public double M
    {
        get { return this._m; }
        set { this._m = value; }
    }

    public double Y
    {
        get { return this._y; }
        set { this._y = value; }
    }

    public double K
    {
        get { return this._k; }
        set { this._k = value; }
    }

    public bool Equals(CMYK cmyk)
    {
        return (this.C == cmyk.C) && (this.M == cmyk.M) && (this.Y == cmyk.Y) && (this.K == cmyk.K);
    }
}

public struct RGB
{
    private byte _r;
    private byte _g;
    private byte _b;

    public RGB(byte r, byte g, byte b)
    {
        this._r = r;
        this._g = g;
        this._b = b;
    }

    public byte R
    {
        get { return this._r; }
        set { this._r = value; }
    }

    public byte G
    {
        get { return this._g; }
        set { this._g = value; }
    }

    public byte B
    {
        get { return this._b; }
        set { this._b = value; }
    }

    public bool Equals(RGB rgb)
    {
        return (this.R == rgb.R) && (this.G == rgb.G) && (this.B == rgb.B);
    }
}

public static RGB CMYKToRGB(CMYK cmyk)
{
    byte r = (byte)(255 * (1 - cmyk.C) * (1 - cmyk.K));
    byte g = (byte)(255 * (1 - cmyk.M) * (1 - cmyk.K));
    byte b = (byte)(255 * (1 - cmyk.Y) * (1 - cmyk.K));

    return new RGB(r, g, b);
}