2010-02-11 59 views
4

我生成条形码生成条形码的工作正常条形码也perfectly.followin读它是条码生成代码:从下面的条形码在ASP.NET中删除文本(C#)

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

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

+1

该代码的输出是什么样的? – 2010-02-11 12:03:25

+0

@Tomas:我的条形码将没有数字(* 50036 *) – Vijjendra 2010-02-11 12:21:43

+0

'orignBitmap'用于什么?是不是从这个图像传来的文字?同样在你的代码中,你正在声明从未使用的'Arial'字体系列。 – 2010-02-11 12:25:00

回答

6

一个更好的选择可能是只使用不具有在首位文本的字体:

尝试这样的:Free Barcode Font - Code 39

+1

+1用于提出替代解决方案,而不是仅仅试图解决问题。 – Tony 2010-02-11 13:00:17

+1

@Nick:尝试以另一种方式实现条形码不是我的问题的答案 – Vijjendra 2010-02-11 13:18:09

+1

@Vijjendra - 我很困惑为什么你想要一个更困难的路线?我的解决方案是下载一个免费的**字体文件,弹出并完成。您宁愿渲染原始字体,绘制矩形或计算字体大小,然后剥下图像?我从来没有见过有人选择到同一解决方案的更复杂或更复杂的路线,所以我对你的评论感到非常疑惑。 – 2010-02-11 13:41:37

1

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

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

8

您可以设置Font = null;删除下面的条码文本。

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

这是正确和可行的答案!我试图设置字体并将AltText设置为String.Empty。它摆脱了文字,但留下了条形码图像后的空间。将字体设置为null完全摆脱了alt。文本和空间。 – 2017-04-13 17:23:51