Convert image to byte array - what am I doing wrong.

Post your Gambas programming questions here.
AndyGable
Posts: 363
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Convert image to byte array - what am I doing wrong.

Post by AndyGable »

Can anyone convert Python code into Gambas Code?

Code: Select all

 def bitmap(self, data, length=0, density=0):
        if length == 0:
            length = len(data)
        if 0 < length < 1023:
            # length_lower = int(length & ord('\xff')).to_bytes()
            # length_higher = int((length & ord('\x03')<<8)>>8).to_bytes()
            
            # self.write(const.ESC_st + bytes(density) + length_lower + length_higher + bytes(data))
            self.write(const.ESC_st + density.to_bytes(1, "little") + length.to_bytes(2, "little") + bytes(data))
        else:
            raise Exception
So the command it's sending concats to
\x1B\x2A + (decimal value for density converted to bytes, assuming darkness or similar, but default is zero, little endian, length 1) + (length of the data converted to bytes, little endian, length 2) + (data, converted to bytes)

This should then print my logo on the Epson Printer (as thanks to vuott code it converts it to Hex data)
Post Reply