2

I am trying to print an image to a Zebra label printer through the serial port using VB6. I have tried various file formats (different bit depths of BMP), getting closest with an image with a bit depth of 4 (something actually prints, doesn't look much like the image I am using though).

I would assume that a bit depth of 1 would be required, as the printer can only print black and white anyway, but I do not get any output when I send my file over. I guess this is due to the printer expecting more data and therefore not starting the print. The code that I currently have is:


Private Type BITMAPFILEHEADER
    bfType As Integer
    bfSize As Long
    bfReserved1 As Integer
    bfReserved2 As Integer
    bfOffBits As Long
End Type

Private Type BITMAPINFOHEADER
    biSize As Long
    biWidth As Long
    biHeight As Long
    biPlanes As Integer
    biBitCount As Integer
    biCompression As Long
    biSizeImage As Long
    biXPelsPerMeter As Long
    biYPelsPerMeter As Long
    biClrUsed As Long
    biClrImportant As Long
End Type

Private Type RGBQUAD
    rgbBlue As Byte
    rgbGreen As Byte
    rgbRed As Byte
    rgbReserved As Byte
End Type

Private Sub cmdImage_Click()
    Dim BMPFileHeader As BITMAPFILEHEADER
    Dim BMPInfoHeader As BITMAPINFOHEADER
    Dim BMPRGBQuad() As RGBQUAD
    Dim fFile As Integer
    Dim bImage() As Byte
    Dim padding As Integer

    fFile = FreeFile
    
    Open "img1.bmp" For Binary Access Read As fFile
        Get fFile, , BMPFileHeader
        Get fFile, , BMPInfoHeader
        Select Case BMPInfoHeader.biBitCount
        Case 1
            ReDim BMPRGBQuad(1)
        Case 4
            ReDim BMPRGBQuad(15)
        Case 8
            ReDim BMPRGBQuad(255)
        End Select
        If BMPInfoHeader.biBitCount &lt 24 Then
            Get fFile, , BMPRGBQuad()
        End If
        ReDim bImage(BMPInfoHeader.biSizeImage)
        Get fFile, , bImage
    Close fFile
    
    padding = 32 - ((BMPInfoHeader.biWidth * BMPInfoHeader.biBitCount) Mod 32)
    If padding = 32 Then padding = 0
    padding = padding \ BMPInfoHeader.biBitCount

    com.output = "N" & vblf
    com.Output = "GW50,50," & (BMPInfoHeader.biWidth + padding) / 8 & "," & BMPInfoHeader.biWidth & ","
    com.Output = bImage
    Send vbLf & "P1,1"
End Sub

Here is the support article on the Zebra website for reference

The printer is accepting my commands, and properly connected. I have no problems printing barcodes etc. The printer is a TLP2742, but I assume the approach would be the same on all printers that use EPL.

Edit: And the EPL Programmers manual

Edit 2: Added mostly working code, here is a question with the same issue as the code above

Community
  • 1
  • 1
Sam
  • 57
  • 9
  • It looks like you at least need 1 bit per pixel. Did you try using a 1bpp bitmap? – Rob Feb 15 '16 at 11:18
  • Tried that, and I get no output with the code above - I was assuming that whatever the output was the printer was expecting more so never starts to print. If I alter the code to `ReDim bImage(BMPFileHeader.bfSize)` then I get a series of diagonal lines, seemingly randomly placed within the 120x120 box my image would take up. – Sam Feb 15 '16 at 11:34
  • Shouldn't it be: BMPInfoHeader.biWidth / 8 & "," & BMPInfoHeader.biHeight & "," I would suggest try sending known bytes. So in your example 120x120 send 1800 bytes (of something, try chr(15) and see if that prints vertical bands) – Rob Feb 15 '16 at 12:35
  • So far correct on all accounts, I have switched the width and height (although that doesn't change anything in my square example), and sending chr(15) does indeed give me vertical bands - with chr(240) being the inverse and chr(51) being twice as many. I have tried sending my array like this `For i = UBound(bImage) - (BMPInfoHeader.biWidth * BMPInfoHeader.biHeight) / 8 To UBound(bImage) com.Output = Chr(bImage(i)) Next i` but so far that only takes me back to the seemingly random diagonal lines. – Sam Feb 15 '16 at 13:52
  • You could just read the data out of the bitmap a byte at a time and send it... – Rob Feb 15 '16 at 14:31
  • Diagonal line issue is related to padding in the file - I can successfully print when the file is of a size where no padding is required (64x64, 128x128 etc) but where padding is needed I was getting the diagonal lines. I will update the original question with new code as to how I arrived at this stage and link to another stack exchange question where my new issue (black bar at the side of the image when padding is required) is solved. Thanks for the help Rob. – Sam Feb 15 '16 at 16:55

0 Answers0