vb.net条形码图像缩放至所需的纸张尺寸 [英] vb.net Bar code image scalling to required paper size
本文介绍了vb.net条形码图像缩放至所需的纸张尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是条形码打印功能:
公共 功能 Code128_Print( ByVal Str As 字符串,
ByVal 价格标签 As 字符串,
ByVal xOffset As 单个,
ByVal yOffset As 单个,
ByVal barHeight As 单个,
ByVal BarWidth As 整数,
ByRef e As PrintPageEventArgs,
ByRef xShowPriceOnImageAt As showStringPositionOnImageAt,
ByRef xShowStringOnImageAt As showStringPositionOnImageAt) As 单
Dim Ret As 字符串,X As 长,CurrChar As As As Dim 线宽 As 整数
Dim barTop As 单个 = 20 . 0 ' 暗 _pen As 新笔(画笔.黑色, 1 )
如果 BarWidth< 1 然后 BarWidth = 1
Ret = " & Replace(Code128_Str(Str)," ," ")
X = 14 * BarWidth
' \\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\此部分创建条形码\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\
做
CurrChar = Left(Ret, 2 )
Ret = Mid(Ret, 3 )
LineWidth = Val(Left(CurrChar, 1 ))
对于 K = 1 >到线宽
对于 Q = 0 >到 BarWidth- 1
Graphics.DrawLine(_pen,X + Q + xOffset,yOffset + barTop,X + Q + xOffset,barHeight + yOffset)
Q = 0 到 BarWidth- 1
e.Graphics.DrawLine(_pen,X + Q + xOffset,yOffset + barTop,X + Q + xOffset,barHeight + yOffset)
下一步 Q
X = X +条宽
下一步 K
X = X +(Val(Mid(CurrChar& " , 1 ))* BarWidth)
循环,直到Len(Ret)= 0
X = X +( 14 * BarWidth)
返回 X
结束 功能
主类形式
导入 System.Drawing.Printing
公共 类 Form1
私有 oPrintDoc As 新建 PrintDocument
私有 oPrnPreviewer As 新建 PrintPreviewControl
私有 oprevwDialog As 新建 PrintPreviewDialog
私有 oPrnDialog As 新建 PrintDialog
私有 oBmp As 位图
私有 Sub doPrint( ByVal 发件人目标 对象, ByVal e 如 PrintPageEventArgs)
Dim oBarCodePrinter As 新 itlBarcodePrinter
oBmp = oBarCodePrinter.Code128_Print(TextToPrint.Text, 100 , 1 ,e)
PictureBox1.Image = oBmp
结束 子
私有 子 Form1_Load( ByVal 发件人目标 对象, ByVal e 句柄 AddHandler oPrintDoc.PrintPage, AddressOf doPrint
结束 子
私有 子 PreviewBCode( ByVal 发件人 As 系统.对象, ByVal e As System.EventArgs)句柄 BeginGraphicPrint.Click
oprevwDialog.Document = oPrintDoc
oprevwDialog.ShowDialog()
结束 子
私有 子 PrintBCode( ByVal 发件人 As 系统.对象, ByVal e As System.EventArgs)句柄 Button1.Click
如果 oPrnDialog.ShowDialog = DialogResult.OK 然后
oPrintDoc.PrinterSettings.PrinterName = oPrnDialog.PrinterSettings.PrinterName
oPrintDoc.Print()
结束 如果
结束 子
私有 子 DoneBtn_Click(发送方 As 系统. 对象,e As System.EventArgs)句柄 DoneBtn.Click
'
结束 子
结束 类
请以获取更多信息,请以为准
' *** Michael Ciurescu(CVMichael)制造***
' 参考:
' http://www.barcodeman.com/info/c128.php3
< \ pre>
解决方案
这是因为条形码读取器对重新缩放非常敏感-条形码通过比较亮条和暗条的相对宽度来工作.重新缩放图像时,将挤压这些条,并且两个连续条的宽度不同.这会降低条形码的质量,很容易使它们变得不可读.
解决方案?不要重新缩放条形码图像.
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:
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>
解决方案
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.
这篇关于vb.net条形码图像缩放至所需的纸张尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文