Click here to Skip to main content
13,085,613 members (72,701 online)
Rate this:
Please Sign up or sign in to vote.
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 thanks.

this is the barcode printing funtion:

    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 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
            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
  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
    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:
Posted 23-Jul-12 3:42am
Updated 23-Jul-12 3:47am
Wes Aday104.2K

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100