Android Question Send Bitmap Data to ESC/POS Printer

Discussion in 'Android Questions' started by infow, Nov 29, 2016.

  1. infow

    infow Member Licensed User


    I tried to adapt the text send to bitmap. Taking the text sample as base, as resquested tryed change the TextWriter to AsyncStreams with no luck... Now I'm not getting any response from the printer.
    For now I´m just focusing in print something, but the idea it's send a bitmap data and print (commented on the code).

    Array As Byte(0x1BAsc("a"), 1))
    Array As Byte(0x1DAsc("*"), imagem.Width/8, imagem.Height))
    For x = 1 To imagem.Width/8 -1
    Array As Byte(255))
            printerA.Write(Array As Byte(0x1DAsc("/"), Asc("0")))
    Array As Byte(0x1BAsc("a"), 1))
    Can a expert in B4A help with this sample?

    Attached Files:

    Last edited: Nov 29, 2016
  2. Erel

    Erel Administrator Staff Member Licensed User

    Start with sending text. Can you post the TextWriter based code that works and the code you tries with AsyncStreams?
  3. infow

    infow Member Licensed User

    Hi Erel,

    I managed to print, it´s quite slow and the print it´s distorted (maybe something about the getpixel order), but it´s printing (saving the bitmap in the printer and printing on sequence)...

    Dim imagem As Bitmap, x As Int, y As Int
            imagem = 
    LoadBitmap(File.DirAssets, "logopol.bmp")
    Dim out As OutputStream
    Array As Byte(0x1D),0,1)
    Array As Byte(0x2A),0,1)
    Array As Byte(imagem.Width/8),0,1)
    Array As Byte(imagem.height),0,1)
    For x = 0 To  p.Length -1
    If p(x) = -1 Then bits = bits & "0" Else bits = bits & "1"
    If p(x) = -1 Then bitslinha = bitslinha & "0" Else bitslinha = bitslinha & "1"
    If bits.Length = 8 Then
                        'count = count + 1
                        'Log(RetBytePOS(bits) & " " & count)
                        out.WriteBytes(Array As Byte(RetBytePOS(bits)),0,1)
                        bits = 
    End If
    If bitslinha.Length = imagem.Width  Then
                        bitslinha = 
    End If            
    Array As Byte(0x1D0x2A00))     
    Array As Byte(0x1DAsc("/"), 3)) 

    Sub RetBytePOS(bitStr As StringAs Int
    If bitStr.Length < 8 Then bitStr = bitStr & "00000000"
    Return (bitStr.SubString2(0,1)*1)+(bitStr.SubString2(1,2)*2)+(bitStr.SubString2(2,3)*4)+(bitStr.SubString2(3,4)*8)+(bitStr.SubString2(4,5)*16)+(bitStr.SubString2(5,6)*32)+(bitStr.SubString2(6,7)*64)+(bitStr.SubString2(7,8)*128)
    End Sub
  4. Carles Escudé

    Carles Escudé Member Licensed User

    Have you finally been able to print a bmp?

    I can print text but can't print a image.

    need some help...

    thanks in advance
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. Carles Escudé

    Carles Escudé Member Licensed User

    Thanks Erel but I have to print a image to a bluetooth printer.

    With this library i get the error:

    B4A version: 5.50
    Parsing code. (0.07s)
    Compiling code. (0.17s)
    Compiling layouts code. (0.00s)
    Generating R file. (0.04s)
    Compiling generated Java code. Error
    Cannot find: C:\Android\libraries\

    Some other option?
  7. Erel

    Erel Administrator Staff Member Licensed User

    This library will work with any printer that provides a printer service app. Many do.

    It requires B4A v6+ and Android 4.4+.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice