Click here to Skip to main content
15,891,184 members
Home / Discussions / C#
   

C#

 
QuestionGraph to image Pin
Abel Castillo21-Jun-06 6:03
Abel Castillo21-Jun-06 6:03 
AnswerRe: Graph to image Pin
mikanu21-Jun-06 6:32
mikanu21-Jun-06 6:32 
GeneralRe: Graph to image Pin
Abel Castillo21-Jun-06 7:08
Abel Castillo21-Jun-06 7:08 
GeneralRe: Graph to image Pin
mikanu21-Jun-06 8:09
mikanu21-Jun-06 8:09 
GeneralRe: Graph to image [modified] Pin
Abel Castillo21-Jun-06 23:15
Abel Castillo21-Jun-06 23:15 
GeneralRe: Graph to image Pin
Abel Castillo22-Jun-06 0:57
Abel Castillo22-Jun-06 0:57 
GeneralRe: Graph to image [modified] Pin
mikanu22-Jun-06 6:37
mikanu22-Jun-06 6:37 
GeneralRe: Graph to image Pin
Abel Castillo22-Jun-06 22:29
Abel Castillo22-Jun-06 22:29 
Hello mikanu,

This is the code:

public System.Drawing.Bitmap CreateBitmap( )
{
  float tempWidth  = ( this.Width  * this.Scale ) * 100 ;
  float tempHeight = ( this.Height * this.Scale ) * 100;

  System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( (int)tempWidth, (int)tempHeight );

  System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp );
  this.DrawEan13Barcode( g, new System.Drawing.Point( 0, 0 ) );
  g.Dispose( );
  return bmp;
}


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;

  // 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,
  this.ProductCode, 
  this.ChecksumDigit );


  string sTemp = sbTemp.ToString( );

  string sLeftPattern = "";

  // Convert the left hand numbers.
  sLeftPattern = ConvertLeftPattern( sTemp.Substring( 0, 7 ) );

  // Build the UPC Code.
  strbEAN13.AppendFormat( "{0}{1}{2}{3}{4}{1}{0}",
  this._sQuiteZone, this._sLeadTail,
  sLeftPattern,  
  this._sSeparator,
  ConvertToDigitPatterns( sTemp.Substring( 7 ), this._aRight ) );

  string sTempUPC = strbEAN13.ToString( );

  float fTextHeight = g.MeasureString( sTempUPC, font ).Height;

  // Draw the barcode lines.
  for( int i = 0; i < strbEAN13.Length; i++ )
  {
  if( sTempUPC.Substring( i, 1 ) == "1" ) 
  {
    if( xStart == pt.X )
        xStart = xPosition;

  // Save room for the UPC number below the bar code.
  if( ( i > 12 && i < 55 ) || ( i > 57 && i < 101 ) )
  // Draw space for the number
  g.FillRectangle( brush, xPosition, yStart, lineWidth, height - fTextHeight );
  else
  // Draw a full line.
  g.FillRectangle( brush, xPosition, yStart, lineWidth, height );  
  }

  xPosition += lineWidth;
  xEnd = xPosition;
  }

  // Draw the upc numbers below the line.
  xPosition = xStart - g.MeasureString( this.CountryCode.Substring( 0, 1 ), font ).Width;
  float yPosition = yStart + ( height - fTextHeight );

  // Draw 1st digit of the country code.
  g.DrawString( sTemp.Substring( 0, 1 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );

  xPosition += ( g.MeasureString( sTemp.Substring( 0, 1 ), font ).Width + 43 * lineWidth ) -
           ( g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width );

  // Draw MFG Number.
  g.DrawString( sTemp.Substring( 1, 6 ), font, brush,  new System.Drawing.PointF( xPosition, yPosition ) );

  xPosition += g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width + ( 11 * lineWidth );

  // Draw Product ID.
  g.DrawString( sTemp.Substring( 7 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );

  // Restore the GraphicsState.
  g.Restore( gs );
}


the difference would be the code of the function DrawEan13Barcode, but I don't know why...

I have carried out many tests, but when I use the graph that returns this function I can show it in a PictureBox but never to save it successfully in a stream.

Excuses my insistence, thanks for your time


Abel Castillo
GeneralRe: Graph to image Pin
mikanu23-Jun-06 9:04
mikanu23-Jun-06 9:04 
GeneralRe: Graph to image Pin
Abel Castillo26-Jun-06 22:01
Abel Castillo26-Jun-06 22:01 
AnswerRe: Graph to image Pin
Josh Smith21-Jun-06 7:06
Josh Smith21-Jun-06 7:06 
Questionc# draw on vidoe Pin
eyale21-Jun-06 5:50
eyale21-Jun-06 5:50 
AnswerRe: c# draw on vidoe Pin
BlackDice21-Jun-06 6:24
BlackDice21-Jun-06 6:24 
GeneralRe: c# draw on vidoe Pin
led mike21-Jun-06 7:15
led mike21-Jun-06 7:15 
GeneralRe: c# draw on vidoe Pin
BlackDice21-Jun-06 7:38
BlackDice21-Jun-06 7:38 
GeneralRe: c# draw on vidoe Pin
led mike21-Jun-06 7:48
led mike21-Jun-06 7:48 
GeneralRe: c# draw on vidoe Pin
eyale22-Jun-06 8:08
eyale22-Jun-06 8:08 
GeneralRe: c# draw on vidoe Pin
led mike22-Jun-06 9:42
led mike22-Jun-06 9:42 
QuestionInstantiate Bitmap object from unmanaged memory/ Memory Allocation ? [modified] Pin
Florian Storck21-Jun-06 5:45
Florian Storck21-Jun-06 5:45 
Questioncheckinf for USB connection Pin
donkaiser21-Jun-06 4:20
donkaiser21-Jun-06 4:20 
QuestionError:- Could not access 'CDO.Message' object. Pin
nachisaravanan21-Jun-06 3:22
nachisaravanan21-Jun-06 3:22 
AnswerRe: Error:- Could not access 'CDO.Message' object. Pin
Not Active21-Jun-06 4:24
mentorNot Active21-Jun-06 4:24 
GeneralRe: Error:- Could not access 'CDO.Message' object. Pin
nachisaravanan21-Jun-06 4:34
nachisaravanan21-Jun-06 4:34 
GeneralRe: Error:- Could not access 'CDO.Message' object. Pin
Not Active21-Jun-06 4:38
mentorNot Active21-Jun-06 4:38 
GeneralRe: Error:- Could not access 'CDO.Message' object. Pin
nachisaravanan21-Jun-06 4:50
nachisaravanan21-Jun-06 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.