Problem:
Using an Android device, without internet / network connection, I have to print images to a bluetooth enabled printer.
Be aware that this is the business case — I cannot use Google Cloud Print, nor can I use PrinterShare or anything else like that. The data generated by the app is medical in nature and must be kept confidential and within the app.
What I’ve accomplished:
Generating PCL data (text only, no images) to send to a bluetooth connection that the printer can process and output.
What I’ve tried:
Generating PCL data (image) using the Android ImageMagick port (found here: https://github.com/paulasiimwe/Android-ImageMagick) and sending the generated PCL data to the bluetooth connection.
Result:
Gibberish, but gibberish that appears to be the right dimensions of the image I am trying to print.
==============
My hypothesis is that there’s something slightly off in my implementation of the conversion, but I’m not sure what it is.
Sample Code:
NOTE: this is proof of concept work and captures an image from the Assets dir, makes it available, and then converts it.
// Attempt to get image file from Assets folder
AssetManager assetManager = context.getAssets();
InputStream istr = assetManager.open("test.jpg");
Bitmap bitmap = BitmapFactory.decodeStream(istr);
// Access External Storage Directory and save file
String root = Environment.getExternalStorageDirectory().toString();
File tempDirectory = new File(root + "/temp");
tempDirectory.mkdirs();
String fileName = "test.jpg";
File file = new File (tempDirectory, fileName);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception exception) {
// Exception found
}
// Capture file of recently saved image, convert to PCL
try{
ImageInfo originalInfo = new ImageInfo(Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp/test.jpg");
MagickImage mImage = new MagickImage(originalInfo);
String newInfoPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/temp/test.pcl";
mImage.setFileName(newInfoPath);
mImage.setImageFormat("pcl");
ImageInfo newInfo = new ImageInfo(newInfoPath);
mImage.writeImage(newInfo);
} catch (MagickException exception) {
// Exception found
}
I then retrieve the PCL file and send it to the bluetooth connection (using another method that works using standard PCL files), but as mentioned the output is gibberish.
I feel like I’m missing something simple, but I’m just not seeing it.
Also, I am seeing the following in LogCat that may / may not be related, but I haven't been able to find any information about resolving this nor can I determine if it's anything more than a warning.
V/Magick: ThrowException
V/Magick: severity: 395
V/Magick: reason: UnableToOpenConfigureFile `policy.xml' @ warning/configure.c/GetConfigureOptions/589
V/Magick: Attempting to read from file /storage/emulated/0/temp/test.jpg
V/Magick: ThrowException
V/Magick: severity: 395
V/Magick: reason: UnableToOpenConfigureFile `magic.xml' @ warning/configure.c/GetConfigureOptions/589
V/Magick: OpenPixelCache()
V/Magick: - cache_info->columns: 144
V/Magick: - cache_info->rows: 144
V/Magick: - cache_info->offset: 0
V/Magick: - cache_info->length: 165888
V/Magick: - length: 207360
V/Magick: - create memory pixel cache
V/Magick: ReadImage completed
Does anyone have any experience with this or can anyone point me in the right direction?