ASP.NET et EAN13

ASP.NET et EAN13 - C#/.NET managed - Programmation

Marsh Posté le 12-12-2005 à 16:16:08    

Salut,
 
Dans une base de données, j'ai un code EAN13 (format code barre standard).
Est-ce qu'il y a une lib ASP.NET (si possible, intégrée au FrameWork ou gratuite) qui permette de faire le rendu de ce champ sous forme d'une image ?
 
-- Edit : mis dans la bonne cat :D --


Message édité par Arjuna le 12-12-2005 à 17:35:32
Reply

Marsh Posté le 12-12-2005 à 16:16:08   

Reply

Marsh Posté le 27-12-2005 à 14:42:35    

Reply

Marsh Posté le 27-12-2005 à 15:09:36    

faudra que je trouve pkoi, le code est tout buggué :)
 
les * 100 de la méthode "getBitmap()" font un code barre perdu dans le coin en haut à gauche d'un BMP énorme :pt1cable:
 
avec *5 à la place, ça marche mieu (*4 ça doit être mieu, mais j'ai pas envie d'y passer la nuit :D)
 

Code :
  1. EAN13.CS : (DLL à part)
  2. #region Using directives
  3. using System;
  4. using System.Text;
  5. #endregion
  6. namespace Ean13Barcode2003
  7. {
  8. public class Ean13
  9. {
  10.  private string _sName = "EAN13";
  11.  private float _fMinimumAllowableScale = .8f;
  12.  private float _fMaximumAllowableScale = 2.0f;
  13.  // This is the nomimal size recommended by the EAN.
  14.  private float _fWidth = 37.29f;
  15.  private float _fHeight = 25.93f;
  16.  private float _fFontSize = 8.0f;
  17.  private float _fScale = 1.0f;
  18.  // Left Hand Digits.
  19.  private string [] _aOddLeft = { "0001101", "0011001", "0010011", "0111101",
  20.            "0100011", "0110001", "0101111", "0111011",
  21.            "0110111", "0001011" };
  22.  private string [] _aEvenLeft = { "0100111", "0110011", "0011011", "0100001",
  23.             "0011101", "0111001", "0000101", "0010001",
  24.             "0001001", "0010111" };
  25.  // Right Hand Digits.
  26.  private string [] _aRight = { "1110010", "1100110", "1101100", "1000010",
  27.          "1011100", "1001110", "1010000", "1000100",
  28.          "1001000", "1110100" };
  29.  private string _sQuiteZone = "000000000";
  30.  private string _sLeadTail = "101";
  31.  private string _sSeparator = "01010";
  32.  private string _sCountryCode = "00";
  33.  private string _sManufacturerCode;
  34.  private string _sProductCode;
  35.  private string _sChecksumDigit;
  36.  public Ean13( )
  37.  {
  38.  }
  39.  public Ean13( string ean13 )
  40.  {
  41.   this.CountryCode = ean13.Substring(0, 2);
  42.   this.ManufacturerCode = ean13.Substring(2, 5);
  43.   this.ProductCode = ean13.Substring(7, 5);
  44.   this.ChecksumDigit = ean13.Substring(12, 1);
  45.  }
  46.  public Ean13( string mfgNumber, string productId )
  47.  {
  48.   this.CountryCode = "00";
  49.   this.ManufacturerCode = mfgNumber;
  50.   this.ProductCode = productId;
  51.   this.CalculateChecksumDigit( );
  52.  }
  53.  public Ean13( string countryCode, string mfgNumber, string productId )
  54.  {
  55.   this.CountryCode = countryCode;
  56.   this.ManufacturerCode = mfgNumber;
  57.   this.ProductCode = productId;
  58.   this.CalculateChecksumDigit( );
  59.  }
  60.  public Ean13( string countryCode, string mfgNumber, string productId, string checkDigit )
  61.  {
  62.   this.CountryCode = countryCode;
  63.   this.ManufacturerCode = mfgNumber;
  64.   this.ProductCode = productId;
  65.   this.ChecksumDigit = checkDigit;
  66.  }
  67.  public void DrawEan13Barcode( System.Drawing.Graphics g, System.Drawing.Point pt )
  68.  {
  69.   float width = this.Width * this.Scale;
  70.   float height = this.Height * this.Scale;
  71.   // EAN13 Barcode should be a total of 113 modules wide.
  72.   float lineWidth = width / 113f;
  73.   // Save the GraphicsState.
  74.   System.Drawing.Drawing2D.GraphicsState gs = g.Save( );
  75.   // Set the PageUnit to Millimeter because all of our measurements are in millimeters.
  76.   g.PageUnit = System.Drawing.GraphicsUnit.Millimeter;
  77.   // Set the PageScale to 1, so a millimeter will represent a true millimeter.
  78.   g.PageScale = 1;
  79.   System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush( System.Drawing.Color.Black );
  80.   float xPosition = 0;
  81.   System.Text.StringBuilder strbEAN13 = new System.Text.StringBuilder( );
  82.   System.Text.StringBuilder sbTemp = new System.Text.StringBuilder( );
  83.   float xStart = pt.X;
  84.   float yStart = pt.Y;
  85.   float xEnd = 0;
  86.   System.Drawing.Font font = new System.Drawing.Font( "Arial", this._fFontSize * this.Scale );
  87.   // Calculate the Check Digit.
  88.   this.CalculateChecksumDigit( );
  89.   sbTemp.AppendFormat( "{0}{1}{2}{3}",
  90.    this.CountryCode,
  91.    this.ManufacturerCode,
  92.    this.ProductCode,
  93.    this.ChecksumDigit );
  94.   string sTemp = sbTemp.ToString( );
  95.   string sLeftPattern = "";
  96.   // Convert the left hand numbers.
  97.   sLeftPattern = ConvertLeftPattern( sTemp.Substring( 0, 7 ) );
  98.   // Build the UPC Code.
  99.   strbEAN13.AppendFormat( "{0}{1}{2}{3}{4}{1}{0}",
  100.    this._sQuiteZone, this._sLeadTail,
  101.    sLeftPattern,
  102.    this._sSeparator,
  103.    ConvertToDigitPatterns( sTemp.Substring( 7 ), this._aRight ) );
  104.   string sTempUPC = strbEAN13.ToString( );
  105.   float fTextHeight = g.MeasureString( sTempUPC, font ).Height;
  106.   // Draw the barcode lines.
  107.   for( int i = 0; i < strbEAN13.Length; i++ )
  108.   {
  109.    if( sTempUPC.Substring( i, 1 ) == "1" )
  110.    {
  111.     if( xStart == pt.X )
  112.      xStart = xPosition;
  113.     // Save room for the UPC number below the bar code.
  114.     if( ( i > 12 && i < 55 ) || ( i > 57 && i < 101 ) )
  115.      // Draw space for the number
  116.      g.FillRectangle( brush, xPosition, yStart, lineWidth, height - fTextHeight );
  117.     else
  118.      // Draw a full line.
  119.      g.FillRectangle( brush, xPosition, yStart, lineWidth, height );
  120.    }
  121.    xPosition += lineWidth;
  122.    xEnd = xPosition;
  123.   }
  124.   // Draw the upc numbers below the line.
  125.   xPosition = xStart - g.MeasureString( this.CountryCode.Substring( 0, 1 ), font ).Width;
  126.   float yPosition = yStart + ( height - fTextHeight );
  127.   // Draw 1st digit of the country code.
  128.   g.DrawString( sTemp.Substring( 0, 1 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );
  129.   xPosition += ( g.MeasureString( sTemp.Substring( 0, 1 ), font ).Width + 43 * lineWidth ) -
  130.    ( g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width );
  131.   // Draw MFG Number.
  132.   g.DrawString( sTemp.Substring( 1, 6 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );
  133.   xPosition += g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width + ( 11 * lineWidth );
  134.   // Draw Product ID.
  135.   g.DrawString( sTemp.Substring( 7 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );
  136.   // Restore the GraphicsState.
  137.   g.Restore( gs );
  138.  }
  139.  public System.Drawing.Bitmap CreateBitmap( )
  140.  {
  141.   float tempWidth = ( this.Width * this.Scale ) * 5 ;
  142.   float tempHeight = ( this.Height * this.Scale ) * 5;
  143.   System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( (int)tempWidth, (int)tempHeight );
  144.   System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp );
  145.   this.DrawEan13Barcode( g, new System.Drawing.Point( 0, 0 ) );
  146.   g.Dispose( );
  147.   return bmp;
  148.  }
  149.  private string ConvertLeftPattern( string sLeft )
  150.  {
  151.   switch( sLeft.Substring( 0, 1 ) )
  152.   {
  153.    case "0":
  154.     return CountryCode0( sLeft.Substring( 1 ) );
  155.    case "1":
  156.     return CountryCode1( sLeft.Substring( 1 ) );
  157.    case "2":
  158.     return CountryCode2( sLeft.Substring( 1 ) );
  159.    case "3":
  160.     return CountryCode3( sLeft.Substring( 1 ) );
  161.    case "4":
  162.     return CountryCode4( sLeft.Substring( 1 ) );
  163.    case "5":
  164.     return CountryCode5( sLeft.Substring( 1 ) );
  165.    case "6":
  166.     return CountryCode6( sLeft.Substring( 1 ) );
  167.    case "7":
  168.     return CountryCode7( sLeft.Substring( 1 ) );
  169.    case "8":
  170.     return CountryCode8( sLeft.Substring( 1 ) );
  171.    case "9":
  172.     return CountryCode9( sLeft.Substring( 1 ) );
  173.    default:
  174.     return "";
  175.   }
  176.  }
  177.  private string CountryCode0( string sLeft )
  178.  {
  179.   // 0 Odd Odd  Odd  Odd  Odd  Odd  
  180.   return ConvertToDigitPatterns( sLeft, this._aOddLeft );
  181.  }
  182.  private string CountryCode1( string sLeft )
  183.  {
  184.   // 1 Odd Odd  Even Odd  Even Even  
  185.   System.Text.StringBuilder sReturn = new StringBuilder( );
  186.   // The two lines below could be replaced with this:
  187.   // sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 2 ), this._aOddLeft ) );
  188.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  189.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aOddLeft ) );
  190.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
  191.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aOddLeft ) );
  192.   // The two lines below could be replaced with this:
  193.   // sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 2 ), this._aEvenLeft ) );
  194.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aEvenLeft ) );
  195.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aEvenLeft ) );
  196.   return sReturn.ToString( );
  197.  }
  198.  private string CountryCode2( string sLeft )
  199.  {
  200.   // 2 Odd Odd  Even Even Odd  Even  
  201.   System.Text.StringBuilder sReturn = new StringBuilder( );
  202.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  203.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aOddLeft ) );
  204.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
  205.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aEvenLeft ) );
  206.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aOddLeft ) );
  207.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aEvenLeft ) );
  208.   return sReturn.ToString( );
  209.  }
  210.  private string CountryCode3( string sLeft )
  211.  {
  212.   // 3 Odd Odd  Even Even Even Odd  
  213.   System.Text.StringBuilder sReturn = new StringBuilder( );
  214.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  215.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aOddLeft ) );
  216.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
  217.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aEvenLeft ) );
  218.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aEvenLeft ) );
  219.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aOddLeft ) );
  220.   return sReturn.ToString( );
  221.  }
  222.  private string CountryCode4( string sLeft )
  223.  {
  224.   // 4 Odd Even Odd  Odd  Even Even  
  225.   System.Text.StringBuilder sReturn = new StringBuilder( );
  226.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  227.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aEvenLeft ) );
  228.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aOddLeft ) );
  229.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aOddLeft ) );
  230.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aEvenLeft ) );
  231.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aEvenLeft ) );
  232.   return sReturn.ToString( );
  233.  }
  234.  private string CountryCode5( string sLeft )
  235.  {
  236.   // 5 Odd Even Even Odd  Odd  Even  
  237.   System.Text.StringBuilder sReturn = new StringBuilder( );
  238.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  239.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aEvenLeft ) );
  240.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
  241.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aOddLeft ) );
  242.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aOddLeft ) );
  243.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aEvenLeft ) );
  244.   return sReturn.ToString( );
  245.  }
  246.  private string CountryCode6( string sLeft )
  247.  {
  248.   // 6 Odd Even Even Even Odd  Odd  
  249.   System.Text.StringBuilder sReturn = new StringBuilder( );
  250.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  251.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aEvenLeft ) );
  252.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
  253.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aEvenLeft ) );
  254.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aOddLeft ) );
  255.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aOddLeft ) );
  256.   return sReturn.ToString( );
  257.  }
  258.  private string CountryCode7( string sLeft )
  259.  {
  260.   // 7 Odd Even Odd  Even Odd  Even
  261.   System.Text.StringBuilder sReturn = new StringBuilder( );
  262.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  263.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aEvenLeft ) );
  264.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aOddLeft ) );
  265.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aEvenLeft ) );
  266.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aOddLeft ) );
  267.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aEvenLeft ) );
  268.   return sReturn.ToString( );
  269.  }
  270.  private string CountryCode8( string sLeft )
  271.  {
  272.   // 8 Odd Even Odd  Even Even Odd  
  273.   System.Text.StringBuilder sReturn = new StringBuilder( );
  274.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  275.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aEvenLeft ) );
  276.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aOddLeft ) );
  277.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aEvenLeft ) );
  278.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aEvenLeft ) );
  279.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aOddLeft ) );
  280.   return sReturn.ToString( );
  281.  }
  282.  private string CountryCode9( string sLeft )
  283.  {
  284.   // 9 Odd Even Even Odd  Even Odd  
  285.   System.Text.StringBuilder sReturn = new StringBuilder( );
  286.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 0, 1 ), this._aOddLeft ) );
  287.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 1, 1 ), this._aEvenLeft ) );
  288.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 2, 1 ), this._aEvenLeft ) );
  289.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 3, 1 ), this._aOddLeft ) );
  290.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 4, 1 ), this._aEvenLeft ) );
  291.   sReturn.Append( ConvertToDigitPatterns( sLeft.Substring( 5, 1 ), this._aOddLeft ) );
  292.   return sReturn.ToString( );
  293.  }
  294.  private string ConvertToDigitPatterns( string inputNumber, string [] patterns )
  295.  {
  296.   System.Text.StringBuilder sbTemp = new StringBuilder( );
  297.   int iIndex = 0;
  298.   for( int i = 0; i < inputNumber.Length; i++ )
  299.   {
  300.    iIndex = Convert.ToInt32( inputNumber.Substring( i, 1 ) );
  301.    sbTemp.Append( patterns[iIndex] );
  302.   }
  303.   return sbTemp.ToString( );
  304.  }
  305.  public void CalculateChecksumDigit( )
  306.  {
  307.   string sTemp = this.CountryCode + this.ManufacturerCode + this.ProductCode;
  308.   int iSum = 0;
  309.   int iDigit = 0;
  310.   // Calculate the checksum digit here.
  311.   for( int i = sTemp.Length; i >= 1; i-- )
  312.   {
  313.    iDigit = Convert.ToInt32( sTemp.Substring( i - 1, 1 ) );
  314.    if( i % 2 == 0 )
  315.    { // odd
  316.     iSum += iDigit * 3;
  317.    }
  318.    else
  319.    { // even
  320.     iSum += iDigit * 1;
  321.    }
  322.   }
  323.   int iCheckSum = ( 10 - ( iSum % 10 )  ) % 10;
  324.   this.ChecksumDigit = iCheckSum.ToString( );
  325.  }
  326.  #region -- Attributes/Properties --
  327.  public string Name
  328.  {
  329.   get
  330.   {
  331.    return _sName;
  332.   }
  333.  }
  334.  public float MinimumAllowableScale
  335.  {
  336.   get
  337.   {
  338.    return _fMinimumAllowableScale;
  339.   }
  340.  }
  341.  public float MaximumAllowableScale
  342.  {
  343.   get
  344.   {
  345.    return _fMaximumAllowableScale;
  346.   }
  347.  }
  348.  public float Width
  349.  {
  350.   get
  351.   {
  352.    return _fWidth;
  353.   }
  354.  }
  355.  public float Height
  356.  {
  357.   get
  358.   {
  359.    return _fHeight;
  360.   }
  361.  }
  362.  public float FontSize
  363.  {
  364.   get
  365.   {
  366.    return _fFontSize;
  367.   }
  368.  }
  369.  public float Scale
  370.  {
  371.   get
  372.   {
  373.    return _fScale;
  374.   }
  375.   set
  376.   {
  377.    if( value < this._fMinimumAllowableScale || value > this._fMaximumAllowableScale )
  378.     throw new Exception( "Scale value out of allowable range.  Value must be between " +
  379.      this._fMinimumAllowableScale.ToString( ) + " and " +
  380.      this._fMaximumAllowableScale.ToString( ) );
  381.    _fScale = value;
  382.   }
  383.  }
  384.  public string CountryCode
  385.  {
  386.   get
  387.   {
  388.    return _sCountryCode;
  389.   }
  390.   set
  391.   {
  392.    while( value.Length < 2 )
  393.    {
  394.     value = "0" + value;
  395.    }
  396.    _sCountryCode = value;
  397.   }
  398.  }
  399.  public string ManufacturerCode
  400.  {
  401.   get
  402.   {
  403.    return _sManufacturerCode;
  404.   }
  405.   set
  406.   {
  407.    _sManufacturerCode = value;
  408.   }
  409.  }
  410.  public string ProductCode
  411.  {
  412.   get
  413.   {
  414.    return _sProductCode;
  415.   }
  416.   set
  417.   {
  418.    _sProductCode = value;
  419.   }
  420.  }
  421.  public string ChecksumDigit
  422.  {
  423.   get
  424.   {
  425.    return _sChecksumDigit;
  426.   }
  427.   set
  428.   {
  429.    int iValue = Convert.ToInt32( value );
  430.    if( iValue < 0 || iValue > 9 )
  431.     throw new Exception( "The Check Digit must be between 0 and 9." );
  432.    _sChecksumDigit = value;
  433.   }
  434.  }
  435.  #endregion -- Attributes/Properties --
  436. }
  437. }
  438. EAN13.ASPX :
  439. <%@ Page language="c#" Codebehind="ean13.aspx.cs" AutoEventWireup="false" Inherits="bci.showEan13" %>
  440. (y en a pas lourd...)
  441. EAN13.ASPX.CS :
  442. using System;
  443. using System.Drawing;
  444. using System.Drawing.Imaging;
  445. using System.Drawing.Drawing2D;
  446. using Ean13Barcode2003;
  447. using System.IO;
  448. namespace bci
  449. {
  450. /// <summary>
  451. /// Summary description for showPict.
  452. /// </summary>
  453. public class showEan13 : System.Web.UI.Page
  454. {
  455.  private void Page_Load(object sender, System.EventArgs e)
  456.  {
  457.   MemoryStream memStream = new MemoryStream();
  458.   Ean13 barCode = new Ean13((string) Session["gencod"]);
  459.   Bitmap bmp = barCode.CreateBitmap();
  460.   bmp.Save(memStream, ImageFormat.Png);
  461.   bmp.Dispose();
  462.   Response.Clear();
  463.   Response.ContentType="image/jpeg";
  464.   memStream.WriteTo(Response.OutputStream);
  465.  }
  466.  #region Web Form Designer generated code
  467.  override protected void OnInit(EventArgs e)
  468.  {
  469.   //
  470.   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  471.   //
  472.   InitializeComponent();
  473.   base.OnInit(e);
  474.  }
  475.  /// <summary>
  476.  /// Required method for Designer support - do not modify
  477.  /// the contents of this method with the code editor.
  478.  /// </summary>
  479.  private void InitializeComponent()
  480.  {   
  481.   this.Load += new System.EventHandler(this.Page_Load);
  482.  }
  483.  #endregion
  484. }
  485. }
  486. Appel :
  487. <img src="ean13.aspx">
  488. Après avoir initialisé une variable de session "gencod" contenant le numéro de code barre à dessiner.
  489. Enjoy.


Message édité par Arjuna le 27-12-2005 à 15:11:03
Reply

Marsh Posté le 27-12-2005 à 15:14:42    

On peut aussi utiliser une variable de query string mais c'est pas bô et des petits cons risquent de faire appel à notre page depuis l'extérieur parcequ'ils ont la fleme de faire leur propre librairie :D
 
(j'en sais quelquechose, j'ai déjà fait ce genre de truc pendant longtemps :D)

Reply

Marsh Posté le 27-12-2005 à 18:06:41    

sinon plus simple : tu dl la font TTF EAN13...

Reply

Marsh Posté le 27-12-2005 à 18:50:50    

Ouais, mais nan, c'est pour mettre sur un site Web, et du coup, si je met le texte tel quel, ça va être pas être exploitable par ceux qui ont pas la police, et si c'est pour générer une image, autant le faire proprement. Ce truc marche plutôt bien, d'autant plus qu'il fait un vrai code barre, c'est à dire que non seulement il affiche les barres, mais met bien le code comme il faut en clair en dessous, avec les séparateurs comme il faut.
 
Deplus, la lib peut me permettre de générer un code EAN13 sans problème puisqu'elle sait calculer le checksum

Reply

Marsh Posté le 27-12-2005 à 20:14:57    

avec la font tu as la possibilité d'utiliser la douchette, qui te genere le code TTF du code barre lue...

Reply

Marsh Posté le 28-12-2005 à 01:09:05    

ben... là aussi... je vois pas trop ton truc enfait

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed