我试了一下,但还是不行,因为他们把多余的去掉。
我是先将图片转为1bit,但有在掉黑边的时候行到它去除黑边的区域的值,然后再填充该区域。
这样就造成了会把多余的部份填充掉。
指导一下,还有没有什么更好的办法。
- RasterImage img = ImageViewer.Image.Clone();
-
- ColorResolutionCommand command = new ColorResolutionCommand();
- command.Mode = ColorResolutionCommandMode.InPlace;
- command.BitsPerPixel = 1;
- command.DitheringMethod = RasterDitheringMethod.None;
- command.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
- command.Colors = 0;
- command.Run(img);
- if (dialog.SelectedType == 1)
- {
- rectList = new List<LeadRect>();
- BorderRemoveCommand command1 = new BorderRemoveCommand();
- //command.BorderRemove += new EventHandler<BorderRemoveCommandEventArgs>(command_BorderRemove_S1);
- command1.Border = BorderRemoveBorderFlags.All;
- command1.Flags = BorderRemoveCommandFlags.UseVariance;
- command1.BorderRemove+=command1_BorderRemove;
- command1.Percent = 20;
- command1.Variance = 3;
- command1.WhiteNoiseLength = 9;
- command1.Run(img);
- }
- if(rectList!=null && rectList.Count>0)
- {
- foreach(var item in rectList)
- {
- RasterImage.MakeRegionEmpty();
- RasterImage.SetRegion(null, new RasterRegion(item), RasterRegionCombineMode.Set);
- FillCommand fillCommand = new FillCommand();
- Color color = string.IsNullOrEmpty(ConfigHelper.GetAppConfig("IforeColor", SystemConst.SYS_CONFIG_PATH)) == true ? Color.FromArgb(255, 255, 255) : ColorTranslator.FromWin32(int.Parse(ConfigHelper.GetAppConfig("IforeColor", SystemConst.SYS_CONFIG_PATH)));
- fillCommand.Color = new RasterColor(color.R, color.G, color.B);
- fillCommand.Run(RasterImage);
- }
- RasterImage.MakeRegionEmpty();
- }
- private List<LeadRect> rectList = null;
- private void command1_BorderRemove(object sender, BorderRemoveCommandEventArgs e)
- {
- rectList.Add(e.BoundingRectangle);
- }
复制代码 |