Print image on the bluetooth printer

KDWKDW USMember ✭✭

I am trying to print a logo on a thermal bluetooth printer with the following command

`foreach (BluetoothDevice d in bthD)
{
if (d.Name.ToString().Trim() == "MPT-III")
{
Java.Util.UUID UUID = Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
BluetoothSocket s = null;
s = d.CreateRfcommSocketToServiceRecord(UUID);

                    var icon = Android.Graphics.BitmapFactory.DecodeResource(Resources, Resource.Drawable.img_p);
                    var ms = new MemoryStream();

                    icon.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 0, ms);
                    var iconBytes = ms.ToArray();

                    IntPtr createRfcommSocket = JNIEnv.GetMethodID(d.Class.Handle, "createRfcommSocket", "(I)Landroid/bluetooth/BluetoothSocket;");
                    IntPtr _socket = JNIEnv.CallObjectMethod(d.Handle, createRfcommSocket, new Android.Runtime.JValue(1));
                    s = Java.Lang.Object.GetObject<BluetoothSocket>(_socket, JniHandleOwnership.TransferLocalRef);

                    bth1.CancelDiscovery();
                    s.Connect();

                    s.OutputStream.Write(iconBytes, 0, iconBytes.Length);
                    s.OutputStream.Close();
                    s.Close();
                }
            }`

Printing so generates

Tagged:

Posts

Sign In or Register to comment.