找回密码
 立即注册

QQ登录

只需一步,快速开始

leadcom

论坛元老

24

主题

96

帖子

2万

积分

论坛元老

积分
27812

活字格认证

[已处理] 去黑边问题

leadcom
论坛元老   /  发表于:2015-9-1 15:32  /   查看:6523  /  回复:8
在leadtools中提供了一个去黑边的命令,但是对图片有要求,必须是黑白图片才行。
在我们的实际应用中,如果该图片不为黑白图片,则需要将图片转换成黑白图,然后再去黑边。图片中的一些数据就会被清除掉。
有没有其它的办法,不但有效的去掉了黑边,而且保留了图片中的其它数据。

图一中去掉了黑边,且图片中的其它数据也得到了保留。
http://pan.baidu.com/s/1kTxSQqV
图二中去掉了黑边,但图片中的其它数据也没有了。
http://pan.baidu.com/s/1i370vFR

8 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2015-9-1 16:55:00
沙发
回复 1楼leadcom的帖子

感谢你的问题反馈,请问当前是通过什么方法实现的呢?能否把Demo发到论坛便于我们重现问题,另外,请附上去除黑边的两个图片。
回复 使用道具 举报
leadcom
论坛元老   /  发表于:2015-9-1 17:03:00
板凳


代码

  1. try
  2.             {
  3.                 BorderRemoveCommand command = new BorderRemoveCommand();
  4.                 //command.BorderRemove += new EventHandler<BorderRemoveCommandEventArgs>(command_BorderRemove_S1);
  5.                 command.Border = BorderRemoveBorderFlags.All;
  6.                 command.Flags = BorderRemoveCommandFlags.UseVariance;
  7.                 command.Percent = 20;
  8.                 command.Variance = 3;
  9.                 command.WhiteNoiseLength = 9;
  10.                 command.Run(ImageViewer.Image);
  11.             }
  12.             catch (Exception ex)
  13.             {

  14.                 if (dialog.ShowDialog() == DialogResult.OK)
  15.                 {
  16.                     ColorResolutionCommand command = new ColorResolutionCommand();
  17.                     command.Mode = ColorResolutionCommandMode.InPlace;
  18.                     command.BitsPerPixel = 1;
  19.                     command.DitheringMethod = RasterDitheringMethod.None;
  20.                     command.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
  21.                     command.Colors = 0;
  22.                     command.Run(ImageViewer.Image);
  23.                     if (dialog.SelectedType == 1)
  24.                     {
  25.                         BorderRemoveCommand command1 = new BorderRemoveCommand();
  26.                         //command.BorderRemove += new EventHandler<BorderRemoveCommandEventArgs>(command_BorderRemove_S1);
  27.                         command1.Border = BorderRemoveBorderFlags.All;
  28.                         command1.Flags = BorderRemoveCommandFlags.UseVariance;
  29.                         command1.Percent = 20;
  30.                         command1.Variance = 3;
  31.                         command1.WhiteNoiseLength = 9;
  32.                         command1.Run(ImageViewer.Image);

  33.                     }
  34.                 }
  35.             }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-2 15:11:00
地板
回复 3楼leadcom的帖子

问题我重现了,问题原因为 BorderRemoveCommand 只能应用于 1 bit 图片。

能否考虑通过后台创建一个需要转换图片的备份,使用 BorderRemoveCommandEventArgs  读取这个区域,处理后和原始图片进行合并来实现这个功能。
回复 使用道具 举报
leadcom
论坛元老   /  发表于:2015-9-2 17:29:00
5#
我试了一下,但还是不行,因为他们把多余的去掉。
我是先将图片转为1bit,但有在掉黑边的时候行到它去除黑边的区域的值,然后再填充该区域。
这样就造成了会把多余的部份填充掉。
指导一下,还有没有什么更好的办法。

  1. RasterImage img = ImageViewer.Image.Clone();
  2.                     
  3.                     ColorResolutionCommand command = new ColorResolutionCommand();
  4.                     command.Mode = ColorResolutionCommandMode.InPlace;
  5.                     command.BitsPerPixel = 1;
  6.                     command.DitheringMethod = RasterDitheringMethod.None;
  7.                     command.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
  8.                     command.Colors = 0;
  9.                     command.Run(img);
  10.                     if (dialog.SelectedType == 1)
  11.                     {
  12.                         rectList = new List<LeadRect>();
  13.                         BorderRemoveCommand command1 = new BorderRemoveCommand();
  14.                         //command.BorderRemove += new EventHandler<BorderRemoveCommandEventArgs>(command_BorderRemove_S1);
  15.                         command1.Border = BorderRemoveBorderFlags.All;
  16.                         command1.Flags = BorderRemoveCommandFlags.UseVariance;
  17.                         command1.BorderRemove+=command1_BorderRemove;
  18.                         command1.Percent = 20;
  19.                         command1.Variance = 3;
  20.                         command1.WhiteNoiseLength = 9;
  21.                         command1.Run(img);
  22.                     }
  23.                     if(rectList!=null &amp;&amp; rectList.Count>0)
  24.                     {
  25.                         foreach(var item in rectList)
  26.                         {
  27.                             RasterImage.MakeRegionEmpty();
  28.                             RasterImage.SetRegion(null, new RasterRegion(item), RasterRegionCombineMode.Set);
  29.                             FillCommand fillCommand = new FillCommand();
  30.                             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)));
  31.                             fillCommand.Color = new RasterColor(color.R, color.G, color.B);
  32.                             fillCommand.Run(RasterImage);
  33.                         }
  34.                         RasterImage.MakeRegionEmpty();
  35.                     }
  36.         private List<LeadRect> rectList = null;

  37.         private void command1_BorderRemove(object sender, BorderRemoveCommandEventArgs e)
  38.         {
  39.             rectList.Add(e.BoundingRectangle);
  40.         }
复制代码
回复 使用道具 举报
leadcom
论坛元老   /  发表于:2015-9-6 10:09:00
6#
顶一下
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-6 15:48:00
7#
回复 6楼leadcom的帖子

抱歉久等了,问题我需要发送给厂商进行调查,有进一步消息回复给你。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-9 13:52:00
8#
回复 6楼leadcom的帖子

请参考附件demo:


关键代码:
  1.   
  2.       private void command_BorderRemove_S1(object sender, BorderRemoveCommandEventArgs e)
  3.         {
  4.             //Faris: Fill border with white in ORIGINAL image.
  5.             originalCopy.SetRegion(null, e.Region, RasterRegionCombineMode.Set);
  6.             FillCommand filler = new FillCommand(RasterColor.White);
  7.             filler.Run(originalCopy);
  8.             originalCopy.MakeRegionEmpty();
  9.         }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-9-17 09:16:00
9#
回复 6楼leadcom的帖子

为了给你提供更优质的服务,请对本次服务进行评分。我们会认真对待你提出的宝贵意见,谢谢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部