Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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);


                    s.OutputStream.Write(iconBytes, 0, iconBytes.Length);

Printing so generates



Sign In or Register to comment.