0

I have an Android POS embedded printer I'm using via Bluetooth.

I'm on .Net Maui 7 application.

I would like to print a bmp image. I'm using the following code :

public async Task PrintImage(string deviceName)
    {
        byte[] imageData;
        string someUrl = "https://...";
        using (var webClient = new WebClient())
        {
            imageData = webClient.DownloadData(someUrl);
        }
    
        byte[] SELECT_BIT_IMAGE_MODE = { 0x1B, 0x2A, 33, (byte)255, 0 };            

        using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter)
        {
            MemoryStream stream = new MemoryStream();
            BluetoothDevice device = (from bd in bluetoothAdapter?.BondedDevices
                                      where bd?.Name == deviceName
                                      select bd).FirstOrDefault();
            try
            {
                using (BluetoothSocket bluetoothSocket = device?.
                    CreateRfcommSocketToServiceRecord(
                    UUID.FromString("00001101-0000-1000-8000-00805f9b34fb")))
                {
                    bluetoothSocket?.Connect();
                    //stream.Write(imageData, 0, imageData.Length);
                    stream.Write(SELECT_BIT_IMAGE_MODE, 0, SELECT_BIT_IMAGE_MODE.Length);
                    stream.Write(imageData, 0, imageData.Length);
                    var bytes = stream.ToArray();
                    bluetoothSocket?.OutputStream.Write(bytes, 0, bytes.Length);
                    bluetoothSocket.Close();
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
    }

The code runs but the result of the printing contains only some strange characters as in the picture.

Here is the image I want to print. It's Black & White :

enter image description here

And the result :

enter image description here

How can I solve that?

halfer
  • 19,824
  • 17
  • 99
  • 186
Thomas Carlton
  • 5,344
  • 10
  • 63
  • 126
  • What does `byte[] SELECT_BIT_IMAGE_MODE = { 0x1B, 0x2A, 33, (byte)255, 0 };` mean? Is the bitmap data formatted in a way that the printer can deal with? What does the documentation of the embedded printer say with regards to printing bitmaps? It looks like the printer interprets the byte array as a series of characters. – Julian Jul 22 '23 at 14:44
  • Thanks @Julian for your comment. SELECT_BIT_IMAGE_MODE is something I found https://stackoverflow.com/questions/42901756/printing-an-image-on-a-bluetooth-printer-in-android that is intended to switch the printer to Image Mode. There is no documentation of the printer and the code is intended to work with several printers using esc/pos commands. "Is the bitmap data formatted in a way that the printer can deal with ?" I mean that's the point. I don't know how to format the image to print correctly. Do you have any idea please ? – Thomas Carlton Jul 22 '23 at 14:58
  • 1
    I really cannot tell. Without this little amount of information and no specs, it's close to impossible to know. Seems like a trial-and-error problem. Do you not have any information regarding the manufacturer and the model at all? – Julian Jul 22 '23 at 15:02
  • 1
    we don't know anything about the printer, what printer languages it supports, what file formats, etc. – Jason Jul 22 '23 at 16:28
  • Looks related to your [previous question on Bluetooth printers](https://stackoverflow.com/questions/76643135/how-to-access-pos-printer-using-net-maui). The valuable feedback from @Jason here was given by them on the other question too. Can you edit both questions with some manufacturer/driver/chip info? – halfer Jul 24 '23 at 16:40
  • @halfer the entire idea is to get a solution that works based on ESC/POS commands. Not necessarily specific to a printer. The other point is that we are talking here about a chinese printer with no documentation, no specs... – Thomas Carlton Jul 25 '23 at 00:57
  • It probably isn't possible to get advice on this here. The best hardware hackers might do is to offer to receive your printer by parcel delivery so they can start poking at it. But you could do more research - are you in a position to gentle disassemble the unit so you can get some chip markings? I am not certain that would open up a new avenue of search engine research, but if you are otherwise totally stuck, it would not hurt (except with the risk of damaging the device, of course). – halfer Jul 26 '23 at 11:11
  • You can follow the ESC/POS specifications from here. [Commands in Code Order](https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=72) There are many types of image printing commands, so why not try them all? Note that this may not always be possible, as some vendors and models have their own specifications. – kunif Jul 27 '23 at 01:12

0 Answers0