【问题标题】:VB.net Printing Image to ZebraVB.net 将图像打印到 Zebra
【发布时间】:2013-10-03 13:49:35
【问题描述】:

我在 VB.net 中有一个位图图像,我想将其打印到 Zebra 打印机,希望使用 ZPLII 代码。我在这里看到了这个例子:Working with bitmaps to a ZPL label printer 没有运气。有人能帮忙吗?为此,我已经把头撞到墙上好几天了。提前致谢!

【问题讨论】:

标签: vb.net image printing zpl-ii


【解决方案1】:

您可以使用字体下载实用程序将图像存储在打印机中,然后使用 ZPL 调用它:

^XA
^FT60,1750^A0B,42,40^XGE:[image_name].GRF^FS
^PQ1,0,1,Y^XZ

【讨论】:

    【解决方案2】:

    我有办法

             Imports System.Drawing
            Imports System.Drawing.Imaging
            Imports System.IO
            Imports System.Runtime.InteropServices
            Imports System.Text
    
            Class CONVERTBITMAP
    
                ''' <summary>
                ''' Return codeZPL of an bitmap
                ''' </summary>
                ''' <param name="BMP2">BITMAP</param>
                ''' <returns></returns>
                Public Shared Function CreateGRF(BMP2 As Bitmap) As String
                    'Dim bmp2 As Bitmap = Nothing
                    Dim bmp As Bitmap = Nothing
                    Dim imgData As BitmapData = Nothing
                    Dim pixels As Byte()
                    Dim x As Integer, y As Integer, width As Integer
                    Dim sb As StringBuilder
                    Dim ptr As IntPtr
                    Try
                        bmp = CONVERTBITMAP.CopyToBpp(BMP2, 1)
                        imgData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.[ReadOnly], PixelFormat.Format1bppIndexed)
                        width = Math.Abs(imgData.Stride)
                        pixels = New Byte(width - 1) {}
                        sb = New StringBuilder(width * bmp.Height * 2)
                        ptr = imgData.Scan0
                        Dim PREVNUM As Integer = 0
                        For y = 0 To bmp.Height - 1
                            Marshal.Copy(ptr, pixels, 0, width)
                            For x = 0 To width - 1
                                If (x + 1) * 8 > bmp.Width Then
                                    Dim DIF As Integer = ((x + 1) * 8) - bmp.Width
                                    Dim NUM As Integer = (2 ^ (DIF - PREVNUM)) - 1
                                    Dim BYTENOT As Byte = Not (CByte(NUM))
                                    PREVNUM = DIF
                                    If NUM < 255 Then
                                        Dim NOTPX As Byte = Not (pixels(x))
                                        Dim CBYTE2 As Byte = CByte(NUM)
                                        Dim STR As Byte = Format("{0:X2}", NOTPX - CBYTE2)
                                        sb.AppendFormat("{0:X2}", CByte(STR))
                                    Else
                                        sb.AppendFormat("{0:X2}", CByte(0))
                                    End If
    
                                Else
                                    sb.AppendFormat("{0:X2}", CByte(Not pixels(x)))
                                End If
    
                            Next
                            PREVNUM = 0
                            ptr = ptr.ToInt64 + imgData.Stride    'DirectCast(ptr.ToInt64() + imgData.Stride), IntPtr)
                        Next
                    Finally
                        If bmp IsNot Nothing Then
                            If imgData IsNot Nothing Then
                                bmp.UnlockBits(imgData)
                            End If
                            bmp.Dispose()
                        End If
                    End Try
                    Return [String].Format("^GFA,{0},{0},{1},", width * y, width) + sb.ToString()
                End Function
            End Class      
    

    那么,为了使用

        public function Create_ZPLImage(my_Image As Image) as string
            return CONVERTBITMAP.CreateGRF(_Image)
        End Sub
    

    为我工作

    【讨论】:

    • 您有一个从某处复制的解决方案。请包含来源的属性。
    • 您的原始答案看起来像是来自Programmer » 1bpp in C# 的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    相关资源
    最近更新 更多