iOS Question print image on ESC/POS Printer

cloner7801

Active Member
Licensed User
Longtime User
You can get the image pixels with this code: https://www.b4x.com/android/forum/t...iewdata-camera-in-an-array.63302/#post-401275 (the post above it includes the code that calls the native method).
I dont have b4a but I open that b4a project with text editor and I found this sub :
B4X:
Sub getPixels(bmp As Bitmap, offset As Int, stride As Int, x As Int, y As Int, width As Int, height As Int) As Int()
    Dim jo = bmp As JavaObject
    Dim pixels(width * height) As Int
    jo.RunMethod("getPixels", Array As Object(pixels, offset, width, x, y, width, height))
    Return pixels
End Sub

Can you convert that code to this kind sub ? to return int() ? to use in this code ? :
B4X:
Dim imagem As Bitmap, x As Int, y As Int
    imagem = LoadBitmap(File.DirAssets, "testebmp3.bmp")

    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    out.WriteBytes(Array As Byte(0x1D),0,1)         'GS
    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)

    Dim  bits As String
    Dim p() As Int
    p = getPixels(imagem, 0, imagem.Width, 0, 0, imagem.Width, imagem.Height)
    For x = 0 To p.Length-1
        If p(x) = -1 Then bits = bits & "0" Else bits = bits & "1"
        If bits.Length = 8 Then
            out.WriteBytes(Array As Byte(RetBytePOS(bits)),0,1)
            bits = ""
        End If
    Next
    Astream.Write(Array As Byte(0x1D, 0x2A, 0, 0))      
    Astream.Write(out.ToBytesArray)
    Astream.Write(Array As Byte(0x1D, Asc("/"), 0))
 
Upvote 0

cloner7801

Active Member
Licensed User
Longtime User
You need to call BitmapToArray. It will return an array of bytes.
I fixed that , but printer print like this attached file

except of print the bitmap
 

Attachments

  • photo_2017-06-08_11-56-25.jpg
    photo_2017-06-08_11-56-25.jpg
    173.9 KB · Views: 619
Upvote 0
Top