【问题标题】:Printooth is not printing the imagePrintooth 不打印图像
【发布时间】:2019-11-10 18:41:58
【问题描述】:
我正在尝试使用Printooth Library 打印enter image description here QR 图像。但问题是它没有按预期打印。
这是我用来创建二维码的代码
try {
qr = QRCode.from("www.example.org").to(ImageType.JPG).bitmap()
} catch (e: WriterException) {
Log.e("Error", "is ${e.message}")
}
我在 imageview 中检查了 QR,没问题。我正在使用此代码进行打印
add(ImagePrintable.Builder(qr).setAlignment(DefaultPrinter.ALIGNMENT_RIGHT)
.build())
and result is in attach image。请帮帮我。
【问题讨论】:
标签:
android
printing
bluetooth
【解决方案1】:
所以我发现我没有将位图图像转换为黑白图像,这很重要,而且是打印机问题。
al.add(new ImagePrintable.Builder(toGrayscale(bitmap))
.setAlignment(DefaultPrinter.Companion.getALIGNMENT_CENTER())
.build());
public static Bitmap toGrayscale(Bitmap srcImage) {
Bitmap bmpGrayscale = Bitmap.createBitmap(srcImage.getWidth(),
srcImage.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmpGrayscale);
Paint paint = new Paint();
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
paint.setColorFilter(new ColorMatrixColorFilter(cm));
canvas.drawBitmap(srcImage, 0, 0, paint);
return bmpGrayscale;
}