Android Question Send Bitmap Data to ESC/POS Printer

infow

Member
Licensed User
Longtime User
Hi,

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).

B4X:
       printerA.Initialize(cmp20.InputStream,cmp20.OutputStream,"PrinterA")
        printerA.Write(Array As Byte(0x1B, Asc("a"), 1))
        printerA.Write(Array As Byte(0x1D, Asc("*"), imagem.Width/8, imagem.Height))
   
        For x = 1 To imagem.Width/8 -1
            printerA.Write(Array As Byte(255))
        Next
        'Log(PrintBuffer)
        printerA.Write(Array As Byte(0x1D, Asc("/"), Asc("0")))
        printerA.Write(Array As Byte(0x1B, Asc("a"), 1))

Can a expert in B4A help with this sample?
 

Attachments

  • WAS Droid.zip
    40.5 KB · Views: 746
Last edited:

infow

Member
Licensed User
Longtime 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)...

B4X:
      Dim imagem As Bitmap, x As Int, y As Int
        imagem = LoadBitmap(File.DirAssets, "logopol.bmp")
     
        Dim out As OutputStream
        out.InitializeToBytesArray(0)
        out.WriteBytes(Array As Byte(0x1D),0,1)
        out.WriteBytes(Array As Byte(0x2A),0,1)
        out.WriteBytes(Array As Byte(imagem.Width/8),0,1)
        out.WriteBytes(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
                    'Log(bits)
                    '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
                    Log(bitslinha)
                    bitslinha = ""
                End If            
         Next
        Log(BytesToString(out.ToBytesArray,0,out.ToBytesArray.Length,"utf-8"))
        Astream.Write(Array As Byte(0x1D, 0x2A, 0, 0))     
        Astream.Write(out.ToBytesArray)
        Astream.Write(Array As Byte(0x1D, Asc("/"), 3)) 

Sub RetBytePOS(bitStr As String) As 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
 
Upvote 0

Carles Escudé

Member
Licensed User
Longtime 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\com.android.support:support-v4.jar

Some other option?
Thanks
 
Upvote 0
Top