asp.net(c#)生成EAN13条形码,webform版本

        做一个项目需要用到条形码,在网上搜索一下,基本上都是winform版本。于是我就找了一个老外的代码修改了一下,版权属于原作者。
          写一个条形码的类,名称为EAN13BarCode.cs,代码如下:
using  System;
using  System.Text;
using  System.Drawing;
using  System.Web;

namespace  Utility
{
    
/// <summary>
    
/// EAN13BarCode 的摘要说明。
    
/// </summary>

    public class EAN13BarCode
    
{
        
private string _sName = "EAN13";

        
private float _fMinimumAllowableScale = .8f;
        
private float _fMaximumAllowableScale = 2.0f;

        
// This is the nomimal size recommended by the EAN.
        private float _fWidth = 37.29f;
        
private float _fHeight = 25.93f;
        
private float _fFontSize = 8.0f;
        
private float _fScale = 1.0f;

        
// Left Hand Digits.
        private string [] _aOddLeft = "0001101""0011001""0010011""0111101"
                                          
"0100011""0110001""0101111""0111011"
                                          
"0110111""0001011" }
;

        
private string [] _aEvenLeft = "0100111""0110011""0011011""0100001"
                                           
"0011101""0111001""0000101""0010001"
                                           
"0001001""0010111" }
;

        
// Right Hand Digits.
        private string [] _aRight = "1110010""1100110""1101100""1000010"
                                        
"1011100""1001110""1010000""1000100"
                                        
"1001000""1110100" }
;

        
private string _sQuiteZone = "000000000";

        
private string _sLeadTail = "101";

        
private string _sSeparator = "01010";

        
private string _sCountryCode = "00";
        
private string _sManufacturerCode;
        
private string _sProductCode;
        
private string _sChecksumDigit;

        
public EAN13BarCode( )
        
{

        }


        
public EAN13BarCode( string mfgNumber, string productId )
        
{
            
this.CountryCode = "00";
            
this.ManufacturerCode = mfgNumber;
            
this.ProductCode = productId;
            
this.CalculateChecksumDigit( );
        }


        
public EAN13BarCode( string countryCode, string mfgNumber, string productId )
        
{
            
this.CountryCode = countryCode;
            
this.ManufacturerCode = mfgNumber;
            
this.ProductCode = productId;
            
this.CalculateChecksumDigit( );
        }


        
public EAN13BarCode( string countryCode, string mfgNumber, string productId, string checkDigit )
        
{
            
this.CountryCode = countryCode;
            
this.ManufacturerCode = mfgNumber;
            
this.ProductCode = productId;
            
this.ChecksumDigit = checkDigit;
        }


        
public static string getENA13Code(string Numbers12bit)
        
{
            
int c1 = 0;
            
int c2 = 0;

            
for (int i=0; i<11;  i= i+2)
            
{
                c1 
+= int.Parse(Numbers12bit[i].ToString());
                c2 
+= int.Parse(Numbers12bit[i+1].ToString());
            }


            
int c3 = c1 + c2 *3;

            c3 
= c3  - c3/10 *10;

            
if (c3 == 0)
            
{
                
return Numbers12bit + 0;
            }

            
else
            
{
                
int N = 10 - c3;

                
return Numbers12bit + N.ToString();
            }

        }

        
public void DrawEan13Barcode(System.Drawing.Graphics g, System.Drawing.Point pt)
        
{
            
float width = this.Width * this.Scale;
            
float height = this.Height * this.Scale;

            
//    EAN13 Barcode should be a total of 113 modules wide.
            float lineWidth = width / 113f;

            g.Clear(Color.White);
            
// Save the GraphicsState.
            System.Drawing.Drawing2D.GraphicsState gs = g.Save( );

            
// Set the PageUnit to Inch because all of our measurements are in inches.
            g.PageUnit = System.Drawing.GraphicsUnit.Millimeter;

            
// Set the PageScale to 1, so a millimeter will represent a true millimeter.
            g.PageScale = 1;

            System.Drawing.SolidBrush brush 
= new System.Drawing.SolidBrush( System.Drawing.Color.Black );

            
float xPosition = 0;

            System.Text.StringBuilder strbEAN13 
= new System.Text.StringBuilder( );
            System.Text.StringBuilder sbTemp 
= new System.Text.StringBuilder( );

            
float xStart = pt.X;
            
float yStart = pt.Y;
            
float xEnd = 0;

            System.Drawing.Font font 
= new System.Drawing.Font( "Arial"this._fFontSize * this.Scale );

            
// Calculate the Check Digit.
            this.CalculateChecksumDigit( );

            sbTemp.AppendFormat( 
"{0}{1}{2}{3}"
                
this.CountryCode,
                
this.ManufacturerCode,
                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值