Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
pls i have a barcode image creation program which needs to be scaled to paper. when it is sent to the printer directly through the printer object, the scanner is able to read the image but when it is sent into a canvas (like a bitmap object to be scaled into the desired paper size) before being sent to the printer, it doesnt read. pls send your response to email@removed.com. thanks.

this is the barcode printing funtion:

VB
    Public Function Code128_Print(ByVal Str As String,
                                  ByVal Pricetag As String,
                                      ByVal xOffset As Single,
                                      ByVal yOffset As Single,
                                    ByVal barHeight As Single,
                                    ByVal BarWidth As Integer,
                                    ByRef e As PrintPageEventArgs,
                                    ByRef xShowPriceOnImageAt As showStringPositionOnImageAt,
                                    ByRef xShowStringOnImageAt As showStringPositionOnImageAt) As Single
        Dim Ret As String, X As Long, CurrChar As String, K As Long, Q As Long
        Dim LineWidth As Integer
        Dim barTop As Single = 20.0                    'This is the vertical starting cordinate of the barcode
        Dim _pen As New Pen(Brushes.Black, 1)

        If BarWidth < 1 Then BarWidth = 1

        Ret = "11" & Replace(Code128_Str(Str), " ", "")
        X = 14 * BarWidth

        '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\This section creates the Barcode \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        Do
            CurrChar = Left(Ret, 2)
            Ret = Mid(Ret, 3)

            LineWidth = Val(Left(CurrChar, 1))
            For K = 1 To LineWidth
                For Q = 0 To BarWidth - 1
                    Graphics.DrawLine(_pen, X + Q + xOffset, yOffset + barTop, X + Q + xOffset, barHeight + yOffset)
 Q = 0 To BarWidth - 1
                    e.Graphics.DrawLine(_pen, X + Q + xOffset, yOffset + barTop, X + Q + xOffset, barHeight + yOffset)
                Next Q
                X = X + BarWidth
            Next K

            X = X + (Val(Mid(CurrChar & "0", 2, 1)) * BarWidth)
        Loop Until Len(Ret) = 0

        X = X + (14 * BarWidth)

        Return X
    End Function


the mainclass form
Imports System.Drawing.Printing

Public Class Form1
    Private oPrintDoc As New PrintDocument
    Private oPrnPreviewer As New PrintPreviewControl
    Private oprevwDialog As New PrintPreviewDialog
    Private oPrnDialog As New PrintDialog

  Private oBmp As Bitmap

  Private Sub doPrint(ByVal sender As Object, ByVal e As PrintPageEventArgs)
    Dim oBarCodePrinter As New itlBarcodePrinter
    oBmp = oBarCodePrinter.Code128_Print(TextToPrint.Text, 100, 1, e)
    PictureBox1.Image = oBmp
  End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    AddHandler oPrintDoc.PrintPage, AddressOf doPrint
    End Sub

  Private Sub PreviewBCode(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeginGraphicPrint.Click
    oprevwDialog.Document = oPrintDoc
    oprevwDialog.ShowDialog()
  End Sub

  Private Sub PrintBCode(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If oPrnDialog.ShowDialog = DialogResult.OK Then
      oPrintDoc.PrinterSettings.PrinterName = oPrnDialog.PrinterSettings.PrinterName
      oPrintDoc.Print()
    End If
  End Sub

  Private Sub DoneBtn_Click(sender As System.Object, e As System.EventArgs) Handles DoneBtn.Click
    '
  End Sub
End Class

please for more info, refer to 

' ***    Made By Michael Ciurescu (CVMichael)   ***
    ' References:
    ' http://www.barcodeman.com/info/c128.php3
<\pre>
Posted
Updated 23-Jul-12 3:47am
v3

1 solution

That is because barcode readers are very sensitive to rescaling - barcodes work by comparing the relative widths of light and dark bars. When you rescale an image, you squash these bars and the widths of two consecutive bars are not the same. This degrades barcode quality, easily to the point at which they become unreadable.

Solution? Don't rescale barcode images.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900