Remove Text from below of the BarCode in ASP.NET(C#)

微笑、不失礼 提交于 2019-12-18 12:46:02

问题


I am generating the barcode generation of barcode is working fine barcode also read it perfectly.followin is the code for barcode generation:

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

Now I want to remove the text which is below of the barcode. how can I do this?.


回答1:


A better alternative might be to just use a font that doesn't have the text in the first place:

Try something like: Free Barcode Font - Code 39




回答2:


You can set Font = null; to remove text below barcode.

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



回答3:


You are creating the barcode using a font and the charcters under the bars are part of that font.

The only way to remove them would be to modify the bitmap (or crop it) after rendering the text; which requires knowing how big the final barcode is. Not impossible to do but a pain.



来源:https://stackoverflow.com/questions/2244225/remove-text-from-below-of-the-barcode-in-asp-netc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!