Zebra Android打印v2.8.2148图像打印为字符串而不是像素

Zebra Android打印v2.8.2148图像打印为字符串而不是像素,android,zebra-printers,Android,Zebra Printers,在我们的android应用程序中,我们可以成功地将图像打印到P4T打印机。我们使用pcx cpcl命令打印与其他收据文本内联的图像。在打印收据之前,我们使用zebra sdk将图像上载到打印机内存。我们让zebra先将位图转换为ZebraImage,然后上传它。在P4T上,这将生成一个.PCX文件,然后我们在cpcl标签中引用该文件。例如: 打印机配置: E:signature.pcx 在android应用程序中: static private void sendImagesToPrinter

在我们的android应用程序中,我们可以成功地将图像打印到P4T打印机。我们使用pcx cpcl命令打印与其他收据文本内联的图像。在打印收据之前,我们使用zebra sdk将图像上载到打印机内存。我们让zebra先将位图转换为ZebraImage,然后上传它。在P4T上,这将生成一个.PCX文件,然后我们在cpcl标签中引用该文件。例如:

打印机配置:

E:signature.pcx
在android应用程序中:

static private void sendImagesToPrinter(DevicePrinter devicePrinter, List<String> imagesToSend, String rootPath) throws IOException, ConnectionException, ZebraPrinterLanguageUnknownException, ZebraIllegalArgumentException {
    for(String image:imagesToSend) {
        //[0] -> image path, <[1]> -> image scale factor
        String[] imageParams = image.split("\\|");
        double scaleFactor = imageParams.length > 1 ? parseImageScale(imageParams[1]) : 1.0d;

        File file = new File(StringUtils.pathCombine(rootPath,imageParams[0]));
        if(!file.exists())
            throw new FileNotFoundException("Image file not found " + file.getName());

        ZebraImageI zebraImage = ZebraImageFactory.getImage(BitmapFactory.decodeFile(file.getAbsolutePath()));

        devicePrinter.storeImage("E:" + file.getName(), zebraImage, (int)(zebraImage.getWidth() * scaleFactor), (int)(zebraImage.getHeight() * scaleFactor));
    }
}

public void storeImage(String printerFullPath, ZebraImageI zebraImage, int width, int height) throws ConnectionException, ZebraPrinterLanguageUnknownException, IOException, ZebraIllegalArgumentException {
    Connection connection = null;
    try {
        connection = ConnectionBuilder.build(connectionString);
        connection.open();
        ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);

        printer.storeImage(printerFullPath, zebraImage, width, height);

    }
    finally {
        if(connection != null)
            connection.close();
    }
}
**编辑
在Qln420上,从未存储映像。我希望它在调用storeImage()后显示在“E:sigfile.pcx”中,但它从未保存。还不知道为什么。

我们的解决方案是在创建用于存储图像的新打印机时显式设置打印机语言:

public void storeImage(String printerFullPath, ZebraImageI zebraImage, int width, int height, PrinterLanguage printerLanguage) throws ConnectionException, ZebraPrinterLanguageUnknownException, IOException, ZebraIllegalArgumentException {
    Connection connection = null;
    try {
        connection = ConnectionBuilder.build(connectionString);
        connection.open();

        ZebraPrinter printer = ZebraPrinterFactory.getInstance(printerLanguage, connection);

        printer.storeImage(printerFullPath, zebraImage, width, height);

    }
    finally {
        if(connection != null)
            connection.close();
    }
}
此外,我们发现删除图像的文件扩展名对一台设备很有帮助,因此我们现在在所有情况下都删除了文件扩展名。 因此,对于我们来说,在P4T、QLn420和ZQ520上打印带有内联图像的CPCL格式收据是可行的

此外,我们发现在存储之前缩放图像也是必要的,因为大型图像存储将失败而不会引发异常

    ZebraImageI zebraImage = ZebraImageFactory.getImage(BitmapFactory.decodeFile(file.getAbsolutePath()));
    double scaleFactor = (printedImageWidth == null) ? 1.0 : (double)printedImageWidth / zebraImage.getWidth();
    //strip off the extension
    String fileName = file.getName().split("\\.")[0];
    devicePrinter.storeImage(fileName, zebraImage, (int)(zebraImage.getWidth() * scaleFactor), (int)(zebraImage.getHeight() * scaleFactor), printerLanguage);

语言设置为什么?对打印机使用以下命令:!U1 getvar“device.languages”您从何处获得的QLn520对我来说是一款新机型…某人输入错误。我不知道目前另一种型号是什么。有QL420,可能是320。ZQ520是另一个设备
public void storeImage(String printerFullPath, ZebraImageI zebraImage, int width, int height, PrinterLanguage printerLanguage) throws ConnectionException, ZebraPrinterLanguageUnknownException, IOException, ZebraIllegalArgumentException {
    Connection connection = null;
    try {
        connection = ConnectionBuilder.build(connectionString);
        connection.open();

        ZebraPrinter printer = ZebraPrinterFactory.getInstance(printerLanguage, connection);

        printer.storeImage(printerFullPath, zebraImage, width, height);

    }
    finally {
        if(connection != null)
            connection.close();
    }
}
    ZebraImageI zebraImage = ZebraImageFactory.getImage(BitmapFactory.decodeFile(file.getAbsolutePath()));
    double scaleFactor = (printedImageWidth == null) ? 1.0 : (double)printedImageWidth / zebraImage.getWidth();
    //strip off the extension
    String fileName = file.getName().split("\\.")[0];
    devicePrinter.storeImage(fileName, zebraImage, (int)(zebraImage.getWidth() * scaleFactor), (int)(zebraImage.getHeight() * scaleFactor), printerLanguage);