views:

299

answers:

2

Hi All, 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

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

+1  A: 

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.

Tony
+6  A: 

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

Nick Craver
+1 for suggesting an alternative solution rather than just trying to fix the problem.
Tony
@Nick: Try to implement Barcode in alternative way is not answer of my question
Vijjendra
@Vijjendra - I'm confused at to why you'd want a more difficult route? My solution is download a **free** font file, pop it in and be done. You'd rather render in your original font, draw rectangles over or calculate font sizes and strip the image down? I've never seen someone choose the far more difficult/complicated route to the same solution, so I'm very puzzled by your comment.
Nick Craver
@Vijjendra: Nick's answer is a valid solution as it only changes the font in use and is much simpler than having to correctly modify the bitmap after rendering the text. I'm interested to know why don't you like his answer?
Tony
@Nick:Thanks it is working now.
Vijjendra