2
    Dim bitmapFilePath As String = imagepath here...
    Dim bitmapFileData As Byte() = System.IO.File.ReadAllBytes(bitmapFilePath)
    Dim fileSize As Integer = bitmapFileData.Length

    Dim bitmapDataOffset As Integer = 0
    Dim width As Integer = 50 '255
    Dim height As Integer = 50 '255
    Dim bitsPerPixel As Integer = 1
    Dim bitmapDataLength As Integer = 400
    Dim widthInBytes As Double = Math.Ceiling(width / 8.0)

    Dim bitmap(bitmapDataLength) As Byte
    Buffer.BlockCopy(bitmapFileData, bitmapDataOffset, bitmap, 0, bitmapDataLength)


    For i As Integer = 0 To bitmapDataLength Step 1
        bitmap(i) = bitmap(i) Xor &HFF

    Next

    Dim ZPLImageDataString As String = BitConverter.ToString(bitmap)
    ZPLImageDataString = Replace(ZPLImageDataString, "-", String.Empty)

    Dim zplCommand(3) As String

    zplCommand(0) = "^XA"
    zplCommand(1) = "^FO20,20"
    zplCommand(2) =
    "^GFA, " +
    bitmapDataLength.ToString() + "," +
    bitmapDataLength.ToString() + "," +
    widthInBytes.ToString() + "," +
    ZPLImageDataString

    zplCommand(3) = "^XZ"

It prints out a nonsense square that looks like someone applied the noise filter in Photoshop. I found this solution on the Zebra website, but that image was 255/255, I need this for a 50/50 image, but I have no idea what I'm supposed to change the offset to or the bitmapDatalength...

Ovi Tisler
  • 6,425
  • 3
  • 38
  • 63
Calvin
  • 710
  • 1
  • 10
  • 28
  • What is your source file? The code looks like it is expecting pure binary image data with no headers. – SSS Jul 10 '12 at 02:21
  • It's a .BMP image, nothing special... http://imgur.com/SsxCL (I think imgur changed it into a png though – Calvin Jul 10 '12 at 12:56

2 Answers2

1

Is your bitmap 1-bit color depth? You can't send color images like this, they need to be converted to b/w 1-bit per pixel. You also need to make sure that your bitmapDataLength variable is correct. This should be the number of bytes of the image to be sent to the printer. See the ^GF command in the ZPL Manual. You can also look in the manual at the example after the ~DG command if you want to save the image on your printer

If you just need to convert a couple images and save them off, you can use the Graphics Conversion Wizard in ZebraNet Bridge. It will take care of the color conversion, and ZPL ^GF math for you and you can also optioinally store the image on your printer.

Ovi Tisler
  • 6,425
  • 3
  • 38
  • 63
  • 1
    Thanks, I think I'm just going to go with the ZebraNet Bridge and call the templates from there. – Calvin Jul 10 '12 at 14:54
1

I had the same problema and solved like this. technically, don't know how, but try it...

Dim bitmapDataLength As Integer = 338 Dim bitmapDataOffset As Integer = 62

The first line represents the image size (file size)in bytes - 62 The second line represents the image's header size (62)

Hope this helps

  • I actually got the above solution to work, but I've jotted down that the header size is 62. I think that's what I was doing wrong. – Calvin Jul 11 '12 at 13:05