Thanks Miky, I'm making other tests and contacting with other programmers, when I find the solution I publish it. cheers Abel Abel Castillo
Abel Castillo
Posts
-
Graph to image -
Graph to imageHello 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 ) ) -
Graph to imagelink Creating EAN-13 Barcodes with C#[^] Abel Castillo
-
Graph to imageI agree with you, I have no problems to save the image to a SQL database and to show it in a PictureBox. But when I tried to save in a array of bytes :( ... I'm working with the code of the excellent article Creating EAN-13 Barcodes with C#[^] by rainman_63. I generate the barcodes of several articles and I need to pass them to a database SQL, I have carried out several tests but up to now without success.
Ean13 ean13 = new Ean13(); ean13.CountryCode = "84"; ean13.ManufacturerCode = "862"; ean13.ProductCode = "3274243"; ean13.ChecksumDigit = "7"; ean13.Scale = 1f; Bitmap bmp = ean13.CreateBitmap(); MemoryStream stream = new MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] buffer = new Byte[stream.Length]; stream.Position = 0; stream.Read(buffer, 0, (int) buffer.Length);
here save barcodes (buffer) in a SQL databasebuffer = null; stream.Close();
Thanks a lot Abel Castillo -- modified at 5:16 Thursday 22nd June, 2006 -
Graph to imageThe image is drawn in another method ("DrawGraphics") but I didn't include it because it is very long this it is a summary of the code: public System.Drawing.Bitmap CreateBitmap( ) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( widthBmp, heightBmp ); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp ); DrawGraphics( g, new System.Drawing.Point( 0, 0 ) ); g.Dispose( ); return bmp; } System.Drawing.Bitmap bmp = CreateBitmap(); // make a memory stream to work with the image bytes MemoryStream stream = new MemoryStream(); // put the image into the memory stream bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); // make byte array the same size as the image byte[] buffer = new Byte[stream.Length]; // rewind the memory stream stream.Position = 0; // load the byte array with the image stream.Read(buffer, 0, (int) buffer.Length); then save the image in sql database, but the array of bytes (variable buffer) has no images, it´s totally black... Thank you for the answer Abel Castillo
-
Graph to imageHi, With images from files or from a database I don't have problems but when I work with images created starting from an object "Graphics" the images don't survive. How can I save this Bitmap?, I tried with: ... System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( widthBmp, heightBmp ); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp ); ... MemoryStream stream = new MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] buffer = new Byte[stream.Length]; stream.Position = 0; stream.Read(buffer, 0, (int) buffer.Length); ... buffer = null; stream.Close(); but the image always is black... Thanks a lot Abel Castillo