Android Java Bixolon SPP-R300 Print Image and Bluetooth

2.3k Views Asked by At

I'm developing application which prints using Bixolon SPP-R300 mobile printer via Bluetooth. I've managed to make the Bluetooth connection, print Text and do lineFeed but i still don't know how to print images. For the text i have this working:

returnValue = mBxlService.PrintText("Text Example",
                BxlService.BXL_ALIGNMENT_LEFT,
                BxlService.BXL_FT_DEFAULT,
                BxlService.BXL_TS_0WIDTH | BxlService.BXL_TS_0HEIGHT);

The mBxlService have a method for image too (mBxlService.PrintImage).

I want to print a image from the drawable folder in the project. Something like drawable/image.png

Someone have worked with this printer or know how to print images with it? There is few information about this, and i'm really trying here.

Other thing is, every time i connect the printer to android a pairing request happens, there is something to bypass that? to do that by code?

This is the printer: Bixolon SPP-R300

Thanks in advance and sorry for my language, English is not my main language.

1

There are 1 best solutions below

0
On

Take a look at this link (it has a snipped of code to print image) Android print image using BIXOLON SPP-R300

And here is the how you can get URI to your resource: how to get an uri of an image resource in android

So, overall code will look something like this:

Uri picturePath = Uri.parse("android.resource://your.package.name/" + R.drawable.image_1);

mBxlService = new BxlService(); 
mBxlService.Connect();
if (mBxlService.GetStatus() == BxlService.BXL_SUCCESS) {
    returnValue = mBxlService.PrintImage(picturePath.toString(), 
                                         384, 
                                         BxlService.BXL_ALIGNMENT_CENTER, 
                                         40);
    if (returnValue == BxlService.BXL_SUCCESS) {
        returnValue = mBxlService.LineFeed(2);                          
    } 
}

Sure, you need to replace "your.package.name" and R.drawable.image_1.

Also, there is a chance that it won't like a path to resources. In such case, I would recommend to spit the image out to SD card and print it from there.