回复 6楼leadcom的帖子
请尝试修改以下代码:
- private void btnReplace_Click(object sender, EventArgs e)
- {
- try
- {
- if (viewer.HasImage == false)
- return;
- RasterColor rasterColor = new RasterColor(txtOldColor.BackColor.A, txtOldColor.BackColor.R, txtOldColor.BackColor.G, txtOldColor.BackColor.B);
- int val = int.Parse(txtValue.Text);
- int a = rasterColor.A * (val / 100);
- int r = rasterColor.R * (val / 100);
- int g = rasterColor.G * (val / 100);
- int b = rasterColor.B * (val / 100);
- RasterColor lowerColor = RasterColor.Create(a, r, g, b);
- //create a region of all dark areas
- viewer.Image.AddColorRgbRangeToRegion(lowerColor, rasterColor, RasterRegionCombineMode.Xor);
- //invert the region so that it covers the non-dark areas
- viewer.Image.AddRectangleToRegion(null, new LeadRect(0, 0, viewer.Image.Width, viewer.Image.Height), RasterRegionCombineMode.Xor);
- FillCommand fill = new FillCommand();
- fill.Color = new RasterColor(txtNewColor.BackColor.A, txtNewColor.BackColor.R, txtNewColor.BackColor.G, txtNewColor.BackColor.B);
- fill.Run(viewer.Image);
- ////clear the region
- viewer.Image.MakeRegionEmpty();
- }
- catch(Exception ex)
- {
- MessageBox.Show("替换出错:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
复制代码
主要是替换 RasterRegionCombineMode.Xor。主要是范围设置导致的问题,请参考:
https://www.leadtools.com/help/l ... ioncombinemode.html
了解替换范围设置。 |