0

I can print plain text, but when I wanna to print image, I cannot print image. I Save image as byte array then send to bluetooth printer. But seen this not work. This is my code

public class PrintServiceRenderer
{
    private static byte[] SELECT_BIT_IMAGE_MODE = { 0x1B, 0x2A, 33, 255, 0 };
    public IList<string> GetDeviceList()
    {
        using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter)
        {
            var btdevice = bluetoothAdapter?.BondedDevices.Select(i => i.Name).ToList();
            return btdevice;
        }
    }
    public async Task Print(string deviceName, byte[] imageData)
    {
        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);
                    var bytes = stream.ToArray();
                    bluetoothSocket?.OutputStream.Write(bytes, 0, bytes.Length);
                    bluetoothSocket.Close();
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
    }
}

But getting logo printed as below image: enter image description here

This is my device: enter image description here

  • I do not know the type/model of printer you are using, but you need to at least write the `SELECT_BIT_IMAGE_MODE` sequence before the image data is sent – SushiHangover Aug 06 '22 at 09:26
  • I use Sunmi V2 device for printing. Information of printing paper and equipment I have attached in the above – Đức Khánh Hoàng Aug 06 '22 at 10:40
  • Not all BT printers are the same. You need to read the docs for your printer and what support it has for printing images, what image formats it supports, resolution, bit depth, etc. and make sure the image you are trying to print conforms to that standard. – Jason Aug 06 '22 at 12:08

0 Answers0