Reputation: 55
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:
Upvotes: 0
Views: 1455