Android 如何在Zebra iMZ320打印机上调整进纸长度以匹配图像高度

Android 如何在Zebra iMZ320打印机上调整进纸长度以匹配图像高度,android,image,printing,zebra-printers,zpl,Android,Image,Printing,Zebra Printers,Zpl,我用的是Zebra iMZ320打印机。我正在尝试从android设备上通过Zebra实用程序应用程序打印PNG图像。有没有办法在不拉伸图像的情况下调整进纸长度以匹配图像高度?目前,我使用Zebra Setup Utility发送到打印机的唯一命令是: !U1“ezpl.媒体类型”“连续” ! U1“ezpl.打印模式”“撕下”有使用ZEBRA iMZ320打印UIImage的完整示例(Objective-C)。我认为,您可以使用相同的打印命令,并用Java或Kotlin编写适当的代码:

我用的是Zebra iMZ320打印机。我正在尝试从android设备上通过Zebra实用程序应用程序打印PNG图像。有没有办法在不拉伸图像的情况下调整进纸长度以匹配图像高度?目前,我使用Zebra Setup Utility发送到打印机的唯一命令是:

!U1“ezpl.媒体类型”“连续”
! U1“ezpl.打印模式”“撕下”

有使用ZEBRA iMZ320打印UIImage的完整示例(Objective-C)。我认为,您可以使用相同的打印命令,并用Java或Kotlin编写适当的代码:

    UIImage *image = ...; //printing image; default wight should be ~572
    id<ZebraPrinterConnection, NSObject> connection = [[MfiBtPrinterConnection alloc] initWithSerialNumber:serialNumber];
    if (![connection open]) {
        NSLog(@"Printer Error! Please check the printer and try it again.");
        return;
    }
    NSError *error = nil;
    id<ZebraPrinter, NSObject> printer = [ZebraPrinterFactory getInstance:connection error:&error];
    PrinterStatus *status = [printer getCurrentStatus:&error];
    if (status == nil) {
        NSLog(@"Error: %@", [error localizedDescription]);
        return;
    } else if (!status.isReadyToPrint) {
        NSLog(@"The printor is not ready to print");
        return;
    }
    CGSize imageSize = image.size;
    //Send configuration command with setting "media_type" = "continuous" and "printing height" = "imageSize.height"
    for (NSString *cmd in @[@"! U1 setvar \"ezpl.media_type\" \"continuous\"\r\n",
                            [NSString stringWithFormat:@"! U1 setvar \"zpl.label_length\" \"%d\"\r\n", (int)imageSize.height]]) {
        if (![[printer getToolsUtil] sendCommand:cmd error:&error]) {
            NSLog(error == nil ? @"Printer Error! Please check the printer and try it again." : [error localizedDescription]));
            return;
        }
    }
    [NSThread sleepForTimeInterval:1];
    if ([[printer getGraphicsUtil] printImage:[image CGImage] atX:0 atY:0 withWidth:-1 withHeight:-1 andIsInsideFormat:false error:&error]) {
        status = [printer getCurrentStatus:&error];
        int i = 0;
        while (!status.isReadyToPrint || i > 30) {
            [NSThread sleepForTimeInterval:1];
            status = [printer getCurrentStatus:&error];
            i++;
        }
        [NSThread sleepForTimeInterval:1];
        NSLog(@"Prining should be success");
    } else {
        NSLog(error == nil ? @"Printer Error! Please check the printer and try it again." : [error localizedDescription]));
    }
    for (NSString *cmd in @[[NSString stringWithFormat:@"! U1 setvar \"zpl.label_length\" \"%d\"\r\n", 50],
                            @"PRINT\r\n"]) {
        [[printer getToolsUtil] sendCommand:cmd error:nil];
    }
    [connection close];
UIImage*image=//印刷图像;默认宽度应为~572
id连接=[[MfiBtPrinterConnection alloc]initWithSerialNumber:serialNumber];
如果(![连接打开]){
NSLog(@“打印机错误!请检查打印机并重试。”);
返回;
}
n错误*错误=nil;
id打印机=[ZebraPrinterFactory getInstance:连接错误:&错误];
PrinterStatus*状态=[printer getCurrentStatus:&错误];
如果(状态==零){
NSLog(@“错误:%@,[Error localizedDescription]);
返回;
}如果(!status.isReadyToPrint),则为else{
NSLog(@“打印机未准备好打印”);
返回;
}
CGSize imageSize=image.size;
//发送设置为“媒体类型”=“连续”和“打印高度”=“图像大小.高度”的配置命令
对于(@[@“!U1 setvar\”ezpl.media\u type\“\”continuous\”\r\n中的NSString*cmd),
[NSString stringWithFormat:@“!U1 setvar\”zpl.label\u length\”\%d\“\r\n”,(int)imageSize.height]]{
if(![[printer getToolsUtil]sendCommand:cmd错误:&错误]){
NSLog(错误==nil?@“打印机错误!请检查打印机并重试。”:[error localizedDescription]);
返回;
}
}
[NSThread sleepForTimeInterval:1];
if([[printer getGraphicsUtil]printImage:[image CGImage]atX:0 atY:0,宽度:-1,高度:-1,侧面格式:错误:&error]){
状态=[printer getCurrentStatus:&错误];
int i=0;
而(!status.isReadyToPrint | | i>30){
[NSThread sleepForTimeInterval:1];
状态=[printer getCurrentStatus:&错误];
i++;
}
[NSThread sleepForTimeInterval:1];
NSLog(@“普林宁应该成功”);
}否则{
NSLog(错误==nil?@“打印机错误!请检查打印机并重试。”:[error localizedDescription]);
}
对于(@[[NSString stringWithFormat:@“!U1 setvar\”zpl.label\U length\”\%d\“\r\n”,50]中的NSString*cmd),
@“打印\r\n”]){
[[printer getToolsUtil]sendCommand:cmd错误:nil];
}
[连接关闭];