图像处理开发工具:LeadTools
打开Visual Studio .NET。点击 文件->新建->项目…。打开新建项目对话框后,在模板中选择“Visual C#”或“Visual Basic”,随后选择“Windows窗体应用程序”。在名称栏中输入项目名称“AdjustColors”,并使用“浏览”按钮选择您工程的存储路径,点击“确定”。
在“解决方案资源管理器”中,右击“引用”,选择“添加引用”。根据当前工程的 Framework 版本和生成目标平台,选择添加相应的LeadTools控件,例如工程中的版本为 Framework 4.0、生成目标平台是 x86,则浏览选择Leadtools For .NET文件夹”
从工具箱(视图->工具箱),添加12个RadioButton控件(将RadioButton的Text属性依照下表修改),两个Panel控件(Name分别修改为panelBefore和panelAfter)。如下图:
切换至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;
将以下变量添加至Form1类: 1: private RasterImageViewer beforePic; 2: private RasterImageViewer afterPic; 3: private RasterCodecs codecs; 4: private RasterImage temp;
添加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'));
双击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);
双击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;
双击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;
双击radioButton4,在radioButton4 CheckedChanged事件句柄中添加以下代码:(本段代码为ChangeHueSaturationIntensityCommand类的使用) 1: temp = beforePic.Image.Clon 2: // 准备命令 3: ChangeHueSaturationIntensit 4: ChangeHueSaturationIntensi 5: 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;
双击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;
双击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;
双击radioButton7,在radioButton7 CheckedChanged事件句柄中添加以下代码:(本段代码为InvertCommand类的使用) 1: temp = beforePic.Image.Clone(); 2: // 准备命令 3: InvertCommand command = new InvertCommand(); 4: //反转图像的颜色 5: command.Run(temp); 6: afterPic.Image = temp;
双击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;
双击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;
双击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;
双击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;
双击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;
编译运行程序,此DEMO使用了LeadTools中12个调整图像色彩的类。运行结果如下: