Getting Byte of an Image

Hi guys,

I am trying to print an image on a printer that supports ESC/POS protocol. To do this, I need to send in the bytes to the printer using ESC/POS protocol. I am following this guide here :

 http://stackoverflow.com/questions/14099239/printing-a-bit-map-image-to-pos-printer-via-comport-in-c-sharp

What I tried so far is to read the image file like this below. 

Is this the correct way to get the actual bytes when I access it using “fileHandle:read( “*a” )” ?

 local filename = 'Icon.bmp' local localDir = system.ResourceDirectory local mime = require "mime" local path if localDir ~= nil then path = system.pathForFile( filename , localDir ) else path = system.pathForFile( filename ) end local fileHandle = io.open( path, "rb" ) local imageRawData if fileHandle then imageRawData = fileHandle:read( "\*a" ) io.close( fileHandle ) end print( imageRawData )

Your file reading code should be correct.

You probably don’t want to use the lua print() statement to dump the data. Once you have imageRawData you can iterate over it using the string byte() command to get each byte and then you can send the bytes to your printer.

Rob

Your file reading code should be correct.

You probably don’t want to use the lua print() statement to dump the data. Once you have imageRawData you can iterate over it using the string byte() command to get each byte and then you can send the bytes to your printer.

Rob