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 :
And the result :
How can I solve that?