2

I have a bitmap image in VB.net that I want to print to a Zebra printer, hopefully using the ZPLII code. I have seen the example here: Working with bitmaps to a ZPL label printer with no luck. Can anyone help with this? I have hit my head against the wall for days on this. Thanks in advance!

Community
  • 1
  • 1
  • Maybe this can help you http://stackoverflow.com/questions/17787620/prepare-a-zpl-command-for-printing-the-mono-chrome-bitmap-image โ€“ RamHS Oct 03 '13 at 13:54

2 Answers2

0

You can use font downloader utility to store the image in the the printer and then recall it using ZPL:

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

i have a solution

         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      

then, for use

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

work for me

henoc salinas
  • 1,044
  • 1
  • 9
  • 20
  • You have a solution that you copied from somewhere. Please include an attribute to the source. โ€“ LarsTech Mar 28 '17 at 20:22
  • Your original answer looked like it had code that came from [Programmer ยป 1bpp in C#](http://www.wischik.com/lu/programmer/1bpp.html). โ€“ LarsTech Jun 14 '17 at 20:31