We can convert an image to a byte array for sending to ESC/POS printer.
I use the code here: https://stackoverflow.com/a/14099717/1853275
it works like charm.
simple question: is it possible to convert this byte array back to original image?
if yes, please tell me how...
bigger picture:
I have created a TCP/IP listener which acts as a POS printer.
It receives data from a POS application and then forwards to real printer.
in between, I have to get the products on the receipt and print something extra based on the products.
so, I need to convert the graphics data to image (then OCR) to read the products on receipt.
here's one captured ESC/POS receipt:
pastebin.com/vUDHjGuj
(we can convert it to byte array, then send to printer. it prints a receipt.)
I know the structure of captured data. we can remove ESC/POS commands and split the array by 0x0A LF. I just need a way to convert the graphics byte arrays to image and put the slices together to create image of receipt.
graphics mode sent to printer is: 24 bit double density (0x1B 0x2A 0x21)
please help...
many thanks
below is one of the pieces I tried, but it gives all black.
I send one slice (byte[]), with width=512 (from captured data), height: 1 (or any)
public static Bitmap FromByteArray(byte[] ByteArray, Size Size)
{
Bitmap bmp = new Bitmap(Size.Width, Size.Height, PixelFormat.Format24bppRgb);
BitmapData bmpdata = bmp.LockBits(new Rectangle(0, 0, Size.Width, Size.Height),ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
IntPtr ptr = bmpdata.Scan0;
System.Runtime.InteropServices.Marshal.Copy(ByteArray, 0, ptr, ByteArray.Length);
bmp.UnlockBits(bmpdata);
return bmp;
}