- LeadTools中文图像处理教程(1):更改数据格式 点击进入
- LeadTools中文图像处理教程(2):图像的几何变换 点击进入
- LeadTools中文图像处理教程(3):倾斜校正 点击进入
- LeadTools中文图像处理教程(4):调整图像亮度和对比度 点击进入
- LeadTools中文图像处理教程(5):图像去噪 点击进入
- LeadTools中文图像处理教程(6):检测和增强边缘、线条 点击进入
- LeadTools中文图像处理教程(7):应用艺术效果 点击进入
- LeadTools中文图像处理教程(8):调整色彩 点击进入
- LeadTools中文图像处理教程(9):添加图像至另一个图像 点击进入
- LeadTools中文图像处理教程(10):窗位(仅用于Medical) 点击进入
- LeadTools中文图像处理教程(11):对比图像 点击进入
LeadTools是全球最优秀的图形、图像处理开发包,它可以处理各种格式的文件,并包含所有图形、图像的处理和转换功能,支持多种平台。
色彩调整是图像处理中非常重要的一部分,LeadTools在调整色彩方面提供了30余个类,具有非常强大的功能,可以帮助您将图像色彩调整到预期的效果。
本博文概览:
1 创建“色彩调整”应用程序的具体步骤
2 LeadTools “色彩调整”相关类简介
3 LeadTools “色彩调整”支持WF的相关活动简介
创建“色彩调整”应用程序的具体步骤
1. 打开Visual Studio .NET。点击 文件->新建->项目…。打开新建项目对话框后,在模板中选择“Visual C#”或“Visual Basic”,随后选择“Windows窗体应用程序”。在名称栏中输入项目名称“AdjustColors”,并使用“浏览”按钮选择您工程的存储路径,点击“确定”。
2. 在“解决方案资源管理器”中,右击“引用”,选择“添加引用”。根据当前工程的 Framework 版本和生成目标平台,选择添加相应的LeadTools控件,例如工程中的版本为 Framework 4.0、生成目标平台是 x86,则浏览选择Leadtools For .NET文件夹” <LEADTOOLS_INSTALLDIR>\Bin\DotNet4\Win32”,选择以下的DLL“:
- Leadtools.dll
- Leadtools.Codecs.dll
- Leadtools.Codecs.Cmp.dll
- Leadtools.ImageProcessing.Core.dll
- Leadtools.ImageProcessing.Color.dll
- Leadtools.ImageProcessing.SpecialEffects.dll
- Leadtools.WinForms.dll
3.从工具箱(视图->工具箱),添加12个RadioButton控件(将RadioButton的Text属性依照下表修改),两个Panel控件(Name分别修改为panelBefore和panelAfter)。如下图:
Name | Text |
radioButton1 | 使用AutoColorLevelCommand 增强图像的阴影和亮度 |
radioButton2 | 使用BumpMapCommand 增加三维纹理图案 |
radioButton3 | 使用ChangeHueCommand 调整色相 |
radioButton4 | 使用ChangeHueSaturationIntensityCommand 处理图像 |
radioButton5 | 使用ColorThresholdCommand 处理灰度图像 |
radioButton6 | 使用ColorIntensityBalanceCommand 处理图像 |
radioButton7 | 使用InvertCommand 处理图像 |
radioButton8 | 使用LensFlareCommand 处理图像 |
radioButton9 | 使用LightCommand 处理图像 |
radioButton10 | 使用SelectiveColorCommand 处理图像 |
radioButton11 | 使用SwapColorsCommand 处理图像 |
radioButton12 | 使用TunnelCommand 处理图像 |
4. 切换至Form1的代码视图(右击Form1,选择查看代码),将下面几行代码添加到文件开始处:
1: using Leadtools;
2: using Leadtools.Codecs;
3: using Leadtools.WinForms;
4: using Leadtools.ImageProcessing.Color;
5: using Leadtools.ImageProcessing.SpecialEffects;
6: using Leadtools.ImageProcessing.Core;
5. 将以下变量添加至Form1类:
1: private RasterImageViewer beforePic;
2: private RasterImageViewer afterPic;
3: private RasterCodecs codecs;
4: private RasterImage temp;
6. 添加Form1 Load事件句柄,在其中添加以下代码:
1: beforePic = new RasterImageViewer();
2: beforePic.BackColor = Color.DarkCyan;3: beforePic.Dock = DockStyle.Fill;4: beforePic.InteractiveMode = RasterViewerInteractiveMode.Pan;5: beforePic.HorizontalAlignMode = RasterPaintAlignMode.Center;6: beforePic.VerticalAlignMode = RasterPaintAlignMode.Center;7: beforePic.AutoResetScaleFactor = false;
8: panelBefore.Controls.Add(beforePic);9: beforePic.BringToFront();10:11: afterPic = new RasterImageViewer();
12: afterPic.BackColor = beforePic.BackColor;13: afterPic.Dock = beforePic.Dock;14: afterPic.InteractiveMode = beforePic.InteractiveMode;15: afterPic.HorizontalAlignMode = beforePic.HorizontalAlignMode;16: afterPic.VerticalAlignMode = beforePic.VerticalAlignMode;17: afterPic.AutoResetScaleFactor = beforePic.AutoResetScaleFactor;18: panelAfter.Controls.Add(afterPic);19: afterPic.BringToFront();20:21: codecs = new RasterCodecs();
22: codecs.ThrowExceptionsOnInvalidImages = true;
23: beforePic.Image = codecs.Load(Path.Combine(Application.StartupPath, @"..\..\Pic\cannon.jpg"));
7.双击radioButton1,在radioButton1 CheckedChanged事件句柄中添加以下代码:
(本段代码为AutoColorLevelCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: AutoColorLevelCommand command = new AutoColorLevelCommand();
4: ommand.Run(temp);5: afterPic.Image = temp;6: codecs.Save(temp, Path.Combine(Application.StartupPath, @"..\..\Pic\AutoColorLevelCommand.jpg"), RasterImageFormat.Jpeg, 24);
8.双击radioButton2,在radioButton2 CheckedChanged事件句柄中添加以下代码:
(本段代码为BumpMapCommand类的使用)
1: temp = beforePic.Image.Clone();2: // 准备命令
3: BumpMapCommand command = new BumpMapCommand();
4: command.Azimuth = 5;5: command.Brightness = 50;6: command.BumpImage = temp;7: command.BumpPoint = new LeadPoint(0, 0);
8: command.Depth = 3;9: command.DestinationPoint = new LeadPoint(0, 0);
10: command.Elevation = 0;11: command.Intensity = 0;12: command.LookupTable = null;
13: command.Tile = true;
14: command.Run(temp);15: afterPic.Image = temp;
9.双击radioButton3,在radioButton3 CheckedChanged事件句柄中添加以下代码:
(本段代码为ChangeHueCommand类的使用)
1: temp = beforePic.Image.Clone();2: ChangeHueCommand command = new ChangeHueCommand();
3: command.Angle = 180;4: command.Run(temp);5: afterPic.Image = temp;
10.双击radioButton4,在radioButton4 CheckedChanged事件句柄中添加以下代码:
(本段代码为ChangeHueSaturationIntensityCommand类的使用)
1: temp = beforePic.Image.Clon2: // 准备命令
3: ChangeHueSaturationIntensit4: ChangeHueSaturationIntensi5: data[0] = new ChangeHueSatu
6: data[0].Hue = 18000;7: data[0].Saturation = 0;8: data[0].Intensity = 0;9: data[0].OuterLow = 315;10: data[0].OuterHigh = 45;11: data[0].InnerLow = 345;12: data[0].InnerHigh = 15;13: command.Data = data;14: command.Hue = 0;15: command.Saturation = 0;16: command.Intensity = 0;17:18: command.Run(temp);19: afterPic.Image = temp;
11.双击radioButton5,在radioButton5 CheckedChanged事件句柄中添加以下代码:
(本段代码为ColorThresholdCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: ColorThresholdCommandComponent[] Components = new ColorThresholdCommandComponent[3];
4:5: Components[0] = new ColorThresholdCommandComponent();
6: Components[0].MinimumRange = 128;7: Components[0].MaximumRange = 255;8: Components[0].Flags = 0;9: Components[1] = new ColorThresholdCommandComponent();
10: Components[1].MinimumRange = 128;11: Components[1].MaximumRange = 255;12: Components[1].Flags = 0;13: Components[2] = new ColorThresholdCommandComponent();
14: Components[2].MinimumRange = 128;15: Components[2].MaximumRange = 255;16: Components[2].Flags = 0;17:18: ColorThresholdCommand command = new ColorThresholdCommand(ColorThresholdCommandType.Rgb, Components);
19: command.Run(temp);20: afterPic.Image = temp;
12.双击radioButton6,在radioButton6 CheckedChanged事件句柄中添加以下代码:
(本段代码为ColorThresholdCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: ColorIntensityBalanceCommand command = new ColorIntensityBalanceCommand();
4: ColorIntensityBalanceCommandData Shadows = new ColorIntensityBalanceCommandData();
5: ColorIntensityBalanceCommandData MidTone = new ColorIntensityBalanceCommandData();
6: ColorIntensityBalanceCommandData HighLight = new ColorIntensityBalanceCommandData()
7:8: Shadows.Red = 60;9: Shadows.Blue = 0;10: Shadows.Green = 0;11:12: MidTone.Red = 40;13: MidTone.Blue = 0;14: MidTone.Green = 0;15:16: HighLight.Red = 70;17: HighLight.Blue = 0;18: HighLight.Green = 0;19:20: command.Shadows = Shadows;21: command.MidTone = MidTone;22: command.HighLight = HighLight;23: command.Luminance = false;
24:25: command.Run(temp);26: afterPic.Image = temp;
13.双击radioButton7,在radioButton7 CheckedChanged事件句柄中添加以下代码:
(本段代码为InvertCommand类的使用)
1: temp = beforePic.Image.Clone();2: // 准备命令
3: InvertCommand command = new InvertCommand();
4: //反转图像的颜色
5: command.Run(temp);6: afterPic.Image = temp;
14.双击radioButton8,在radioButton8 CheckedChanged事件句柄中添加以下代码:
(本段代码为LensFlareCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: LensFlareCommand command = new LensFlareCommand();
4:5: command.CenterPoint = new LeadPoint(temp.Width / 4, temp.Height / 4);
6: command.Brightness = 100;7: command.Type = LensFlareCommandType.Type1;8: command.Color = new RasterColor(100, 150, 10);
9:10: command.Run(temp);11: afterPic.Image = temp;
15.双击radioButton9,在radioButton9 CheckedChanged事件句柄中添加以下代码:
(本段代码为LightCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: LightCommandData[] Data = new LightCommandData[1];
4: Data[0].Angle = 0;5: Data[0].CenterPoint = new LeadPoint(temp.Width / 2, temp.Height / 2);
6: Data[0].Edge = 0;7: Data[0].Brightness = 100;8: Data[0].FillColor = new RasterColor(255, 255, 255);
9: Data[0].Height = Math.Min(temp.Height, temp.Width) / 2;10: Data[0].Width = Math.Min(temp.Height, temp.Width) / 2;11: Data[0].Opacity = 100;12: Data[0].Type = LightCommandType.Spot;13:14: LightCommand command = new LightCommand();
15: command.Ambient = 100;16: command.Bright = 100;17: command.Data = Data;18: command.AmbientColor = new RasterColor(255, 255, 255);
19: command.Run(temp);20: afterPic.Image = temp;
16.双击radioButton10,在radioButton10 CheckedChanged事件句柄中添加以下代码:
(本段代码为SelectiveColorCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: SelectiveColorCommand command = new SelectiveColorCommand();
4:5: command.ColorsData[(int)SelectiveCommandColorTypes.Red].Cyan = -100;
6: command.ColorsData[(int)SelectiveCommandColorTypes.Yellow].Cyan = 34;
7: command.ColorsData[(int)SelectiveCommandColorTypes.Yellow].Magenta = 100;
8: command.ColorsData[(int)SelectiveCommandColorTypes.Yellow].Yellow = 40;
9: command.ColorsData[(int)SelectiveCommandColorTypes.Green].Black = 100;
10: command.ColorsData[(int)SelectiveCommandColorTypes.Neutral].Cyan = -65;
11: command.ColorsData[(int)SelectiveCommandColorTypes.Neutral].Magenta = -39;
12: command.ColorsData[(int)SelectiveCommandColorTypes.Neutral].Yellow = 63;
13: command.Run(temp);14: afterPic.Image = temp;
17.双击radioButton11,在radioButton11 CheckedChanged事件句柄中添加以下代码:
(本段代码为SwapColorsCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: SwapColorsCommand command = new SwapColorsCommand();
4: command.Type = SwapColorsCommandType.RedGreen;5: command.Run(temp);6: afterPic.Image = temp;
18.双击radioButton12,在radioButton12 CheckedChanged事件句柄中添加以下代码:
(本段代码为TunnelCommand类的使用)
1: temp = beforePic.Image.Clone();2:3: TunnelCommand command = new TunnelCommand();
4: command.CenterPoint = new LeadPoint(temp.Width / 2, temp.Height / 2);
5: command.ZValue = 0;6: command.Distance = temp.Height;7: command.Radius = temp.Width / 2;8: command.Repeat = -1;9: command.RotationOffset = 0;10: command.Stretch = 25;11: command.StartBright = 0;12: command.EndBright = 100;13: command.BrightLength = 20000;14: command.BrightColor = new RasterColor(255, 255, 255);
15: command.FillColor = new RasterColor(0, 0, 0);
16: command.Flags = TunnelCommandFlags.WidthAxis | TunnelCommandFlags.Color;17: command.Run(temp);18: afterPic.Image = temp;
19. 编译运行程序,此DEMO使用了LeadTools中12个调整图像色彩的类。运行结果如下:
若想了解LeadTools调整色彩的更多类,请继续阅读文章下一部分!
请在本文结尾处下载DEMO!
LeadTools调整色彩的命令类
类名 |
目标 |
在特定图像上应用抗混叠滤波器。 |
|
在图像的颜色上执行特定的数学或逻辑运算。 |
|
使暗值更暗,亮值更亮,自动增强图像的阴影和亮度。 |
|
在RGB、YUV或灰度颜色空间线性化图像中像素的数目 |
|
将凹凸图像应用于目标图像,增加了三维纹理图案。 |
|
通过旋转色轮改变图像中颜色的色调。 |
|
提高或降低图像中颜色的饱和度 |
|
重新平衡图像中的颜色来调整颜色,调整比其他图像颜色更多的图像。 |
|
改变图像中所有或特定颜色的色相、饱和度和亮度。这个方法结合了ChangeHueCommand, ChangeSaturationCommand和 ChangeIntensityCommand的功能,允许您同时修改全部的色相、饱和度和亮度,您也可以单独调整参数,在连续传值过程中进行调整。 |
|
通过调整色相、饱和度和亮度替换特定的颜色。 |
|
使用八个色彩空间中的任意一个重置这些图像的像素值,这个值会落在指定区域的内部或外部。 |
|
改变红色、绿色和蓝色通道的分布。 |
|
给8位、12位或16位灰度图像涂色。这个方法将图像的位/像素从特定格式转换为24位RGB格式。 |
|
在图像中应用色彩调节功能。它改变了图像的阴影、中间色调和高光。 |
|
在Cubist样式中,将图像重新映射为一系列的旋转矩形(立方面)。 |
|
在图像上绘制一个星星。 |
|
模拟水彩干刷技术绘制图像的效果。 |
|
将图像包裹到一个3D面上 |
|
将图像按着曲线塑造的3D平面的半径包裹。 |
|
将图像划分为矩形的单元格,仿佛通过玻璃块在查看图像。 |
|
使图像的彩色边缘闪耀着着霓虹灯的光芒。 |
|
在特定图像中反转颜色,使图片看起来像照片底片。 |
|
模拟亮光遇到相机镜头的二次反射效果。 |
|
在图像中添加定向光源的若干个点 |
|
通过重新映射像素值,调亮或调暗图像的全部或一部分 |
|
将图像反射到一个海洋平面上。 |
|
将图像沿着Z轴放置在平行平面,并朝着中心点弯曲。 |
|
将图像沿着Z轴放置在平行平面。 |
|
将样本颜色改变为目标颜色来校正颜色值。 |
|
通过改变图像中一个或多个颜色的定义改变图像的颜色。 |
|
平滑图像中的毛边。 |
|
选择一个8位、12位或16位灰度图像指定数目的位数,将它们放到一个遮罩中,然后根据遮罩给图像上色。这可以根据用户定义的条件显示图像的差异。 |
|
选择一个8位、12位或16位灰度图像指定数目的位数,将它们放到一个遮罩中,并将这个遮罩应用于新的8位、12位或16位灰度图像。 |
|
在图像中交换颜色通道。 |
|
使用lookup表格改变颜色的色相值 |
|
以指定的颜色代替像素中的红色分量。在图像中只替换眼睛区域的像素,因此需在眼部周围选择一个小的区域。 |
|
沿Z轴将图像放置在一个通道里。 |
支持WF
以下的活动用于调整图像中的颜色:
类名 |
目标 |
在特定图像中反转颜色,使图片看起来像照片底片。 |
DEMO下载:
本文只是提供了用LeadTools来调整图像色彩的一个基本用例,如果你想尝试更多的效果,如平滑图像中的毛边、三维纹理、将图像包裹到一个3D面上等,欢迎下载下载LeadTools全功能试用版,并在本文中的例子代码上进行修改。很简单的,你来试一试吧。
若您在使用LeadTools的过程中遇到任何问题,欢迎在葡萄城开发者社区LeadTools板块提问,我们的专业技术团队期待您的到来!