This project has moved and is read-only. For the latest updates, please go here.

Example of bug in Code 128 generator

Topics: Code 128
Aug 9, 2010 at 6:45 AM
Create file barcode.ashx 
<%@ WebHandler Language="VB" Class="barcode" %>

Imports System
Imports System.Data.Linq
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Web
Imports Zen.Barcode

Public Class barcode : Implements IHttpHandler
	Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
		Const text As String = "LD000324704"
		Const Resolution As Integer = 1
		Const Height As Integer = 75
		Dim Response As HttpResponse = context.Response
		Response.BufferOutput = True
		Response.ContentType = "image/png"

		Dim pict As Byte()
		Using ms As New MemoryStream
			Using Image As Image = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128).Draw(text, Height, Height, (Resolution + 1) * 2, (Resolution + 1) * 3)
				Image.Save(ms, ImageFormat.Png)
			End Using
			pict = ms.ToArray
		End Using

		Response.OutputStream.Write(pict, 0, pict.Length)
	End Sub
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
			Return True
        End Get
    End Property
End Class
Create page Test.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
	<img alt="" src="barcode.ashx" width="220px" height="75px" />

Open this page in browser and print it. I have 5 different types of scanners like Symbol and Cipher and no one of them can not read this printed barcode.
I generated this barcode by DevExpress which this scanners read OK. It's easy to see a little difference in these barcodes.
You can find these test barcodes as PNG here