C# NETRGB颜色操作辅助类.docx

上传人:b****7 文档编号:24050342 上传时间:2023-05-23 格式:DOCX 页数:24 大小:17.43KB
下载 相关 举报
C# NETRGB颜色操作辅助类.docx_第1页
第1页 / 共24页
C# NETRGB颜色操作辅助类.docx_第2页
第2页 / 共24页
C# NETRGB颜色操作辅助类.docx_第3页
第3页 / 共24页
C# NETRGB颜色操作辅助类.docx_第4页
第4页 / 共24页
C# NETRGB颜色操作辅助类.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

C# NETRGB颜色操作辅助类.docx

《C# NETRGB颜色操作辅助类.docx》由会员分享,可在线阅读,更多相关《C# NETRGB颜色操作辅助类.docx(24页珍藏版)》请在冰豆网上搜索。

C# NETRGB颜色操作辅助类.docx

C#NETRGB颜色操作辅助类

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Drawing;

namespaceCommons.Format

{

#regionPublicStructs

publicstructMyColor

{

publicRGBRGB;

publicHSBHSB;

publicCMYKCMYK;

publicMyColor(Colorcolor)

{

this.RGB=color;

this.HSB=color;

this.CMYK=color;

}

publicstaticimplicitoperatorMyColor(Colorcolor)

{

returnnewMyColor(color);

}

publicstaticimplicitoperatorColor(MyColorcolor)

{

returncolor.RGB;

}

publicstaticbooloperator==(MyColorleftMyColorright)

{

return(left.RGB==right.RGB)&&(left.HSB==right.HSB)&&(left.CMYK==right.CMYK);

}

publicstaticbooloperator!

=(MyColorleftMyColorright)

{

return!

(left==right);

}

publicvoidRGBUpdate()

{

this.HSB=this.RGB;

this.CMYK=this.RGB;

}

publicvoidHSBUpdate()

{

this.RGB=this.HSB;

this.CMYK=this.HSB;

}

publicvoidCMYKUpdate()

{

this.RGB=this.CMYK;

this.HSB=this.CMYK;

}

publicoverridestringToString()

{

returnString.Format("{0}\r\n{1}\r\n{2}"RGBHSBCMYK);

}

publicoverrideintGetHashCode()

{

returnbaxxxxse.GetHashCode();

}

publicoverrideboolEquals(obxxxxjectobj)

{

returnbaxxxxse.Equals(obj);

}

}

publicstructRGB

{

privateintred;

privateintgreen;

privateintblue;

publicintRed

{

get{returnred;}

set{red=ColorHelper.CheckColor(value);}

}

publicintGreen

{

get{returngreen;}

set{green=ColorHelper.CheckColor(value);}

}

publicintBlue

{

get{returnblue;}

set{blue=ColorHelper.CheckColor(value);}

}

publicRGB(intredintgreenintblue)

:

this()

{

this.Red=red;

this.Green=green;

this.Blue=blue;

}

publicRGB(Colorcolor)

{

this=newRGB(color.Rcolor.Gcolor.B);

}

publicstaticimplicitoperatorRGB(Colorcolor)

{

returnnewRGB(color.Rcolor.Gcolor.B);

}

publicstaticimplicitoperatorColor(RGBcolor)

{

returncolor.ToColor();

}

publicstaticimplicitoperatorHSB(RGBcolor)

{

returncolor.ToHSB();

}

publicstaticimplicitoperatorCMYK(RGBcolor)

{

returncolor.ToCMYK();

}

publicstaticbooloperator==(RGBleftRGBright)

{

return(left.Red==right.Red)&&(left.Green==right.Green)&&(left.Blue==right.Blue);

}

publicstaticbooloperator!

=(RGBleftRGBright)

{

return!

(left==right);

}

publicoverridestringToString()

{

returnString.Format("Red:

{0}Green:

{1}Blue:

{2}"RedGreenBlue);

}

publicstaticColorToColor(intredintgreenintblue)

{

returnColor.FromArgb(redgreenblue);

}

publicColorToColor()

{

returnToColor(RedGreenBlue);

}

publicstaticHSBToHSB(Colorcolor)

{

HSBhsb=newHSB();

intMaxMin;

if(color.R>color.G){Max=color.R;Min=color.G;}

else{Max=color.G;Min=color.R;}

if(color.B>Max)Max=color.B;

elseif(color.B

intDiff=Max-Min;

hsb.Brightness=(double)Max/255;

if(Max==0)hsb.Saturation=0;

elsehsb.Saturation=(double)Diff/Max;

doubleq;

if(Diff==0)q=0;

elseq=(double)60/Diff;

if(Max==color.R)

{

if(color.G

elsehsb.Hue=q*(color.G-color.B)/360;

}

elseif(Max==color.G)hsb.Hue=(120+q*(color.B-color.R))/360;

elseif(Max==color.B)hsb.Hue=(240+q*(color.R-color.G))/360;

elsehsb.Hue=0.0;

returnhsb;

}

publicHSBToHSB()

{

returnToHSB(this);

}

publicstaticCMYKToCMYK(Colorcolor)

{

CMYKcmyk=newCMYK();

doublelow=1.0;

cmyk.Cyan=(double)(255-color.R)/255;

if(low>cmyk.Cyan)

low=cmyk.Cyan;

cmyk.Magenta=(double)(255-color.G)/255;

if(low>cmyk.Magenta)

low=cmyk.Magenta;

cmyk.Yellow=(double)(255-color.B)/255;

if(low>cmyk.Yellow)

low=cmyk.Yellow;

if(low>0.0)

{

cmyk.Key=low;

}

returncmyk;

}

publicCMYKToCMYK()

{

returnToCMYK(this);

}

publicoverrideintGetHashCode()

{

returnbaxxxxse.GetHashCode();

}

publicoverrideboolEquals(obxxxxjectobj)

{

returnbaxxxxse.Equals(obj);

}

}

publicstructHSB

{

privatedoublehue;

privatedoublesaturation;

privatedoublebrightness;

publicdoubleHue

{

get{returnhue;}

set{hue=ColorHelper.CheckColor(value);}

}

publicdoubleHue360

{

get{returnhue*360;}

set{hue=ColorHelper.CheckColor(value/360);}

}

publicdoubleSaturation

{

get{returnsaturation;}

set{saturation=ColorHelper.CheckColor(value);}

}

publicdoubleSaturation100

{

get{returnsaturation*100;}

set{saturation=ColorHelper.CheckColor(value/100);}

}

publicdoubleBrightness

{

get{returnbrightness;}

set{brightness=ColorHelper.CheckColor(value);}

}

publicdoubleBrightness100

{

get{returnbrightness*100;}

set{brightness=ColorHelper.CheckColor(value/100);}

}

publicHSB(doublehuedoublesaturationdoublebrightness)

:

this()

{

this.Hue=hue;

this.Saturation=saturation;

this.Brightness=brightness;

}

publicHSB(inthueintsaturationintbrightness)

:

this()

{

this.Hue360=hue;

this.Saturation100=saturation;

this.Brightness100=brightness;

}

publicHSB(Colorcolor)

{

this=RGB.ToHSB(color);

}

publicstaticimplicitoperatorHSB(Colorcolor)

{

returnRGB.ToHSB(color);

}

publicstaticimplicitoperatorColor(HSBcolor)

{

returncolor.ToColor();

}

publicstaticimplicitoperatorRGB(HSBcolor)

{

returncolor.ToColor();

}

publicstaticimplicitoperatorCMYK(HSBcolor)

{

returncolor.ToColor();

}

publicstaticbooloperator==(HSBleftHSBright)

{

return(left.Hue==right.Hue)&&(left.Saturation==right.Saturation)&&(left.Brightness==right.Brightness);

}

publicstaticbooloperator!

=(HSBleftHSBright)

{

return!

(left==right);

}

publicoverridestringToString()

{

returnString.Format("Hue:

{0}Saturation:

{1}Brightness:

{2}"ColorHelper.Round(Hue360)

ColorHelper.Round(Saturation100)ColorHelper.Round(Brightness100));

}

publicstaticColorToColor(HSBhsb)

{

intMid;

intMax=ColorHelper.Round(hsb.Brightness*255);

intMin=ColorHelper.Round((1.0-hsb.Saturation)*(hsb.Brightness/1.0)*255);

doubleq=(double)(Max-Min)/255;

if(hsb.Hue>=0&&hsb.Hue<=(double)1/6)

{

Mid=ColorHelper.Round(((hsb.Hue-0)*q)*1530+Min);

returnColor.FromArgb(MaxMidMin);

}

if(hsb.Hue<=(double)1/3)

{

Mid=ColorHelper.Round(-((hsb.Hue-(double)1/6)*q)*1530+Max);

returnColor.FromArgb(MidMaxMin);

}

if(hsb.Hue<=0.5)

{

Mid=ColorHelper.Round(((hsb.Hue-(double)1/3)*q)*1530+Min);

returnColor.FromArgb(MinMaxMid);

}

if(hsb.Hue<=(double)2/3)

{

Mid=ColorHelper.Round(-((hsb.Hue-0.5)*q)*1530+Max);

returnColor.FromArgb(MinMidMax);

}

if(hsb.Hue<=(double)5/6)

{

Mid=ColorHelper.Round(((hsb.Hue-(double)2/3)*q)*1530+Min);

returnColor.FromArgb(MidMinMax);

}

if(hsb.Hue<=1.0)

{

Mid=ColorHelper.Round(-((hsb.Hue-(double)5/6)*q)*1530+Max);

returnColor.FromArgb(MaxMinMid);

}

returnColor.FromArgb(000);

}

publicstaticColorToColor(doublehuedoublesaturationdoublebrightness)

{

returnToColor(newHSB(huesaturationbrightness));

}

publicColorToColor()

{

returnToColor(this);

}

publicoverrideintGetHashCode()

{

returnbaxxxxse.GetHashCode();

}

publicoverrideboolEquals(obxxxxjectobj)

{

returnbaxxxxse.Equals(obj);

}

}

publicstructCMYK

{

privatedoublecyan;

privatedoublemagenta;

privatedoubleyellow;

privatedoublekey;

publicdoubleCyan

{

get{returncyan;}

set{cyan=ColorHelper.CheckColor(value);}

}

publicdoubleCyan100

{

get{returncyan*100;}

set{cyan=ColorHelper.CheckColor(value/100);}

}

publicdoubleMagenta

{

get{returnmagenta;}

set{magenta=ColorHelper.CheckColor(value);}

}

publicdoubleMagenta100

{

get{returnmagenta*100;}

set{magenta=ColorHelper.CheckColor(value/100);}

}

publicdoubleYellow

{

get{returnyellow;}

set{yellow=ColorHelper.CheckColor(value);}

}

publicdoubleYellow100

{

get{returnyellow*100;}

set{yellow=ColorHelper.CheckColor(value/100);}

}

publicdoubleKey

{

get{returnkey;}

set{key=ColorHelper.CheckColor(value);}

}

publicdoubleKey100

{

get{returnkey*100;}

set{key=ColorHelper.CheckColor(value/100);}

}

publicCMYK(doublecyandoublemagentadoubleyellowdoublekey)

:

this()

{

this.Cyan=cyan;

this.Magenta=magenta;

this.Yellow=yellow;

this.Key=key;

}

publicCMYK(intcyanintmagentaintyellowintkey)

:

this()

{

this.Cyan100=cyan;

this.Magenta100=magenta;

this.Yellow100=yellow;

this.Key100=key;

}

publicCMYK(Colorcolor)

{

this=RGB.ToCMYK(color);

}

publicstaticimplicitoperatorCMYK(Colorcolor)

{

returnRGB.ToCMYK(color);

}

publicstaticimplicitoperatorColor(CMYKcolor)

{

returncolor.ToColor();

}

publicstaticimplicitoperatorRGB(CMYKcolor)

{

returncolor.ToColor();

}

publicstaticimplicitoperatorHSB(CMYKcolor)

{

returncolor.ToColor();

}

publicstaticbooloperator==(CMYKleftCMYKright)

{

return(left.Cyan==right.Cyan)&&(left.Magenta==right.Magenta)&&(left.Yellow==right.Yellow)&&

(left.Key==right.Key);

}

publicstaticbooloperator!

=(CMYKleftCMYKright)

{

return!

(left==right);

}

publicoverridestringToString()

{

returnString.Format("Cyan:

{0}Magenta:

{1}Yellow:

{2}Key:

{3}"ColorHelper.Round(Cyan100)

ColorHelper.Round(Magenta100)ColorHelper.Round(Yellow100

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 唐诗宋词

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1