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

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

    Code:
    printerA.Initialize(cmp20.InputStream,cmp20.OutputStream,"PrinterA")
            printerA.Write(
    Array As Byte(0x1BAsc("a"), 1))
            printerA.Write(
    Array As Byte(0x1DAsc("*"), 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(0x1DAsc("/"), Asc("0")))
            printerA.Write(
    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)...

    Code:
    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(0x1D0x2A00))     
            Astream.Write(out.ToBytesArray)
            Astream.Write(
    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

    Hi!
    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\com.android.support:support-v4.jar


    Some other option?
    Thanks
     
  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+.
     
Loading...
  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