【问题标题】:Remove Text from below of the BarCode in ASP.NET(C#)在 ASP.NET(C#) 中从条码下方删除文本
【发布时间】:2016-06-29 19:21:06
【问题描述】:

我正在生成条码的条码生成工作正常条码也可以完美读取。以下是条码生成的代码:

private void GenerateBarCode(string codeInfo)
{
    //Settings for the Image
    string TypeFaceName = "IDAutomationHC39M";
    string imageLocation = Server.MapPath("2010.png");
    //The format of the image file
    ImageFormat format = ImageFormat.Png;
    //path of unique file name    
    string path = "D://MyProjects//RepeaterPaging//images//vijendra.png";
    //REFERENCING A FONT 
    PrivateFontCollection fnts = new PrivateFontCollection();
    fnts.AddFontFile("IDAutomationHC39M.ttf");
    FontFamily fntfam = new FontFamily(TypeFaceName);
    Font fnt = new Font(fntfam, 13);
    fnts.AddFontFile("Arial.ttf");
    FontFamily fntfam2 = new FontFamily("Arial", fnts);
    //DRAWING THE IMAGE  
    Bitmap bmp = new Bitmap(960, 386);           //Canvas size
    Graphics g = Graphics.FromImage(bmp);
    Bitmap orignBitmap = new Bitmap(imageLocation);
    g.Clear(Color.Transparent); //Background color
    SizeF bc = g.MeasureString(codeInfo, fnt);
    Brush br = new SolidBrush(Color.Black);
    g.DrawImage(orignBitmap, 10, 8);
    g.DrawString(codeInfo, fnt, br, 585, 170); //Drawing the Image
    g.TextRenderingHint= 
    bmp.Save(path, format); //Saving the Image file
    bmp.Dispose(); //Releasing all resources (Image file) 
    Response.Clear();
}

alt text http://www.freeimagehosting.net/uploads/0e033f305b.png

现在我想删除条形码下方的文字。 我该怎么做?。

【问题讨论】:

  • 该代码的输出是什么样的?
  • @Tomas:我的条码将没有数字(50036)
  • orignBitmap 是干什么用的?文字不是来自这张图片吗?同样在您的代码中,您声明了从未使用过的 Arial 字体系列。
  • @Darin - 条形码是一种字体,他需要在画完条形码后画一个白色的矩形来隐藏数字。
  • @Nick,仅仅因为条形码是一种字体,当您DrawString 时,它不会编写人类可读的文本,它会绘制条形图。这就是为什么我想知道这段文字来自哪里。

标签: c# asp.net barcode


【解决方案1】:

您可以设置Font = null; 删除条形码下方的文字。

Barcode128 code128 = new Barcode128();
code128.CodeType = Barcode.CODE128;
code128.Code = "123456789";
code128.Font = null;

【讨论】:

  • 这是正确且有效的答案!我尝试设置字体并将 AltText 设置为 String.Empty。它摆脱了文本,但在条形码图像之后留下了空间。将字体设置为 null 完全摆脱了 alt。文字和空格。
  • 谢谢谢谢谢谢!我花了半天时间才找到你的答案:|。在 VB.NET 中,使用:code128.Font = Nothing
  • 救生员!!! iText 的文档从未提到过这样的事情。非常感谢!
【解决方案2】:

更好的选择可能是只使用一开始就没有文本的字体:

尝试类似:Free Barcode Font - Code 39

【讨论】:

  • +1 用于建议替代解决方案,而不仅仅是尝试解决问题。
  • @Nick:尝试以替代方式实施条形码不是我问题的答案
  • @Vijjendra - 我很困惑为什么你想要一条更困难的路线?我的解决方案是下载一个 free 字体文件,将其弹出并完成。您宁愿以原始字体呈现,在上面绘制矩形或计算字体大小并将图像剥离?我从来没有见过有人选择更困难/复杂得多的途径来获得相同的解决方案,所以我对您的评论感到非常困惑。
  • @Vijjendra:Nick 的回答是一个有效的解决方案,因为它只会更改正在使用的字体,并且比渲染文本后必须正确修改位图要简单得多。我很想知道你为什么不喜欢他的回答?
【解决方案3】:

您正在使用一种字体创建条形码,而条形下方的字符是该字体的一部分。

删除它们的唯一方法是在渲染文本后修改位图(或裁剪它);这需要知道最终的条形码有多大。不是不可能,而是很痛苦。

【讨论】:

    猜你喜欢
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 2012-01-24
    • 1970-01-01
    相关资源
    最近更新 更多