Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi Friends,

i m working on project in which client need to genrate barcode image for there product.i don't have any idea about it.if any budy know that how to genrate barcode image & save it into database as image or print it.

Thanks & Regards
Hussain
Posted 4-Jun-12 20:21pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

public void DrawingBarcode(string strNumber)
        {
            PrivateFontCollection fonts = new PrivateFontCollection();  
            //39码
            strNumber = "*" + strNumber + "*";
            fonts.AddFontFile(HttpContext.Current.Server.MapPath(".") + "/BarcodeFonts/FREE3OF9.TTF");
            FontFamily ff = new FontFamily("Free 3 of 9", fonts);         
            Font font = new Font(ff, 12);
 
<pre>
        //设置图片大小
         System.Drawing.Image img =  new Bitmap(1, 1);
        Graphics g = Graphics.FromImage(img);
        SizeF fontSize = g.MeasureString(strNumber, font);
        int intWidth = Convert.ToInt32(fontSize.Width);
        int intHeight = Convert.ToInt32(fontSize.Height);
        g.Dispose();
        img.Dispose();
 
        img = new Bitmap(intWidth, intHeight);
        g = Graphics.FromImage(img);
        g.Clear(Color.White);
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.DrawString(strNumber, font, Brushes.Black, 0, 0);
        MemoryStream stream = new MemoryStream();
        img.Save(stream, ImageFormat.Jpeg);
        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.ContentType = "image/Jpeg";
        HttpContext.Current.Response.BinaryWrite(stream.ToArray());
        g.Dispose();
        img.Dispose();
    }</pre>
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hussain,
If you plan on using a library for generating the Barcode, you can use either a free library or a commercial library. There are a lot of articles on Codeproject for both cases.
Please see the following article for a example on a free generation library:
Barcodes in ASP.NET applications
Please see the following article for a example on a commercial barcode library:
How to Read Barcodes from Images using LEADTOOLS
The above example is for reading Barcodes but the library can be used to generate Barcode.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Hi:
It's convenient to generate barcodes in .net using C#.

1,Unzip BizCode Generator for .NET Ultimate package;
2,Add BusinessRefinery.Barcode.Web.dll to you ASP.NET project folder;
(The DLL will be copied to the bin directory automatically)
3,Then BusinessRefinery.Barcode.Web.dll is added on your ASP.NET project

Here is a sample coding:

using BusinessRefinery.Barcode;

Linear barcode = new Linear();
barcode.Symbology = Symbology.CODE39;
barcode.Code = "0123456789";
barcode.DisplayStartStopChar = true;
barcode.Resolution = 104;
barcode.Rotate = Rotate.Rotate180;
barcode.Format = ImageFormat.Gif;
barcode.drawBarcode2ImageFile("c:/code-39-csharp.gif");

You can cutomize it based on your needs.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

[Spam content has been removed]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210
0 OriginalGriff 490
1 Sergey Alexandrovich Kryukov 405
2 Maciej Los 285
3 ProgramFOX 265
4 Peter Leow 210


Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100