来自 Web 服务 (SOAP) 生成器的 iPhone 条形码图像呈现显示为空白?

发布于 2024-11-09 16:17:46 字数 8422 浏览 4 评论 0原文

我在 webservicesx.net 上找到了一个条形码生成器,它使用 SOAP 接口来请求条形码图像。它支持多种格式Code_2_5_interleaved或Code_2_5_induscial或Code_2_5_matrix或Code39或Code39Extended或Code128A或Code128B或Code128C或Code93或Code93Extended或CodeMSI或CodePostNet或CodeCodabar或CodeEAN8或CodeEAN13或CodeUPC_A或CodeUPC_E0或CodeUPC_E1或CodeUPC_Supp2或CodeUPC_Supp5或CodeEAN128A或CodeEAN128B或CodeEAN128C。数据以 Base64 编码的二进制形式返回。我已经通过以下其他帖子实现了 Base64 的 NSData 接口,例如 NSData 的 Base64 接口。我使用JMeter来验证参数和请求语法。响应返回一个合理的数据字符串,并且(希望)我已经解码了响应并将其正确分配给 UIImage,但我最终得到了一个空白图像。

以下是 SOAP 信封设置以及 webservicex.net 网站上针对此 API 的注释。我已经尝试了几十种变体。我的怀疑仍然围绕颜色和背景颜色参数。我找不到参数值的详细信息。我尝试过 Black、White、black、white、ffffff、000000 等。

还包括 NSURL 的初始化:

    soapEnvelope = [[NSMutableString alloc] initWithString:
                          @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];

[soapEnvelope appendString:@"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"];
[soapEnvelope appendString:@"<soap12:Body>"];
[soapEnvelope appendString:@"<GenerateBarCode xmlns=\"http://www.webservicex.net/\">"];
[soapEnvelope appendString:@"<BarCodeParam>"];
[soapEnvelope appendFormat:@"<Height>%d</Height>", 120];
[soapEnvelope appendFormat:@"<Width>%d</Width>", 120];
[soapEnvelope appendFormat:@"<Angle>%d</Angle>", 0];
[soapEnvelope appendFormat:@"<Ratio>%d</Ratio>", 1];
[soapEnvelope appendFormat:@"<Module>%d</Module>", 1];
[soapEnvelope appendFormat:@"<Left>%d</Left>", 20];
[soapEnvelope appendFormat:@"<Top>%d</Top>", 20];
[soapEnvelope appendFormat:@"<CheckSum>%s</CheckSum>", "true"];
[soapEnvelope appendFormat:@"<FontName>%@</FontName>", @"Helvetica"];
[soapEnvelope appendFormat:@"<BarColor>%@</BarColor>", @"yellow"];
[soapEnvelope appendFormat:@"<BGColor>%@</BGColor>", @"black"];
[soapEnvelope appendFormat:@"<FontSize>%f</FontSize>", 10.0f];
[soapEnvelope appendFormat:@"<barcodeOption>%@</barcodeOption>", @"Code"];
[soapEnvelope appendFormat:@"<barcodeType>%@</barcodeType>", @"Code39"];
[soapEnvelope appendFormat:@"<checkSumMethod>%@</checkSumMethod>", @"None"];
[soapEnvelope appendFormat:@"<showTextPosition>%@</showTextPosition>", @"BottomCenter"];
[soapEnvelope appendFormat:@"<BarCodeImageFormat>%@</BarCodeImageFormat>", @"PNG"];
[soapEnvelope appendFormat:@"<BarCodeText>%@</BarCodeText>", [dictArgs objectForKey:@"barcodetext"] ];
[soapEnvelope appendString:@"</BarCodeParam>"];
[soapEnvelope appendString:@"</GenerateBarCode>"];
[soapEnvelope appendString:@"</soap12:Body>"];
[soapEnvelope appendString:@"</soap12:Envelope>"];
/*
 POST /genericbarcode.asmx HTTP/1.1
 Host: www.webservicex.net
 Content-Type: application/soap+xml; charset=utf-8
 Content-Length: length

 <?xml version="1.0" encoding="utf-8"?>
 <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
 <soap12:Body>
 <GenerateBarCode xmlns="http://www.webservicex.net/">
 <BarCodeParam>
 <Height>int</Height>
 <Width>int</Width>
 <Angle>int</Angle>
 <Ratio>int</Ratio>
 <Module>int</Module>
 <Left>int</Left>
 <Top>int</Top>
 <CheckSum>boolean</CheckSum>
 <FontName>string</FontName>
 <BarColor>string</BarColor>
 <BGColor>string</BGColor>
 <FontSize>float</FontSize>
 <barcodeOption>None or Code or Typ or Both</barcodeOption>
 <barcodeType>Code_2_5_interleaved or Code_2_5_industrial or Code_2_5_matrix or Code39 or Code39Extended or Code128A or Code128B or Code128C or Code93 or Code93Extended or CodeMSI or CodePostNet or CodeCodabar or CodeEAN8 or CodeEAN13 or CodeUPC_A or CodeUPC_E0 or CodeUPC_E1 or CodeUPC_Supp2 or CodeUPC_Supp5 or CodeEAN128A or CodeEAN128B or CodeEAN128C</barcodeType>
 <checkSumMethod>None or Modulo10</checkSumMethod>
 <showTextPosition>TopLeft or TopRight or TopCenter or BottomLeft or BottomRight or BottomCenter</showTextPosition>
 <BarCodeImageFormat>BMP or EMF or EXIF or GIF or ICON or JPEG or MemoryBMP or PNG or TIFF or WMF</BarCodeImageFormat>
 </BarCodeParam>
 <BarCodeText>string</BarCodeText>
 </GenerateBarCode>
 </soap12:Body>
 </soap12:Envelope>     
*/

// ref: for example, http://www.webservicex.net/genericbarcode.asmx?WSDL
urlRequest = [[NSURL alloc] initWithScheme:@"http" host:@"www.webservicex.net" 
                                      path:@"/genericbarcode.asmx?op=GenerateBarCode"];

这是围绕解码和分配的最后阶段的片段:

NSURLRequest *urlThread = (NSMutableURLRequest*) object;

byteImageBarcode = [[NSMutableData alloc] init];
[byteImageBarcode setLength:0];
[byteImageBarcode appendData:
 [NSURLConnection sendSynchronousRequest:urlThread returningResponse:&response error:&error]];

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:byteImageBarcode];

。 。 。

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    NSLog(@"%s [%@]", __FUNCTION__, string);

    NSLog(@"\n\n%s\n\n", elementGenerateBarCodeResult ? "Convert Image Data" : "hmmm ... element not GenerateBarCodeResult");

    if (elementGenerateBarCodeResult) {
        NSData *nsdata = [NSData dataWithBase64EncodedString: string];

        NSLog(@"%s [%@]", __FUNCTION__, nsdata);

        imageBarcode = [[UIImage alloc] initWithData: nsdata];

    }

以下

是 NSData 的转储(在调试器控制台中),它是转换后的图像二进制文件。现在我修复了foundCharacters中的“追加”,图像不再是白色,它是我的视图背景的颜色。这是否意味着我有一个完全透明的图像或一个太小而无法显示的图像?!有人可以解码它以确定它是否是有效的 PNG 二进制文件? (注意:我发现了这个很酷的转换工具:在此处输入链接描述并且我注意到当我将以下数据放入翻译器中,翻译后的值为 (hex)89,后跟 PNG cr-lf,

但我的 UIImage 大小未呈现为 宽度 x 高度。 = (240.00,240.00)。

    Printing description of byteImageBarcode:
<89504e47 0d0a1a0a 0000000d 49484452 000000f0 000000f0 08060000 003e55e9 92000000 01735247 4200aece 1ce90000 00046741 4d410000 b18f0bfc 61050000 00206348 524d0000 7a260000 80840000 fa000000 80e80000 75300000 ea600000 3a980000 17709cba 513c0000 069e4944 4154785e edd6090d c0401003 b12b7fd0 fd588ce2 4310391b b5d7fdbe e31120d0 14f806ec 1120d014 38cdd852 1320f0ff 3d632040 a02b60c0 ddee2427 e00bec06 0894057c 81cbedc9 3e2f60c0 f32700a0 2c60c0e5 f6649f17 30e0f913 00501630 e0727bb2 cf0b18f0 fc090028 0b1870b9 3dd9e705 0c78fe04 0094050c b8dc9eec f302063c 7f0200ca 02065c6e 4ff67901 039e3f01 00650103 2eb727fb bc8001cf 9f0080b2 800197db 937d5ec0 80e74f00 4059c080 cbedc93e 2f60c0f3 2700a02c 60c0e5f6 649f1730 e0f91300 501630e0 727bb2cf 0b18f0fc 0900280b 1870b93d d9e7050c 78fe0400 94050cb8 dc9eecf3 02063c7f 0200ca02 065c6e4f f6790103 9e3f0100 6501032e b727fbbc 8001cf9f 0080b280 0197db93 7d5ec080 e74f0040 59c080cb edc93e2f 60c0f327 00a02c60 c0e5f664 9f1730e0 f9130050 1630e072 7bb2cf0b 18f0fc09 00280b18 70b93dd9 e7050c78 fe040094 050cb8dc 9eecf302 063c7f02 00ca0206 5c6e4ff6 7901039e 3f010065 01032eb7 27fbbc80 01cf9f00 80b28001 97db937d 5ec080e7 4f004059 c080cbed c93e2f60 c0f32700 a02c60c0 e5f6649f 1730e0f9 13005016 30e0727b b2cf0b18 f0fc0900 280b1870 b93dd9e7 050c78fe 04009405 0cb8dc9e ecf30206 3c7f0200 ca02065c 6e4ff679 01039e3f 01006501 032eb727 fbbc8001 cf9f0080 b2800197 db937d5e c080e74f 004059c0 80cbedc9 3e2f60c0 f32700a0 2c60c0e5 f6649f17 30e0f913 00501630 e0727bb2 cf0b18f0 fc090028 0b1870b9 3dd9e705 0c78fe04 0094050c b8dc9eec f302063c 7f0200ca 02065c6e 4ff67901 039e3f01 00650103 2eb727fb bc8001cf 9f0080b2 800197db 937d5ec0 80e74f00 4059c080 cbedc93e 2f60c0f3 2700a02c 60c0e5f6 649f1730 e0f91300 501630e0 727bb2cf 0b18f0fc 0900280b 1870b93d d9e7050c 78fe0400 94050cb8 dc9eecf3 02063c7f 0200ca02 065c6e4f f6790103 9e3f0100 6501032e b727fbbc 8001cf9f 0080b280 0197db93 7d5ec080 e74f0040 59c080cb edc93e2f

I found a barcode generator at webservicesx.net that uses a SOAP interface to request a barcode image. It supports a myriad of formats <barcodeType>Code_2_5_interleaved or Code_2_5_industrial or Code_2_5_matrix or Code39 or Code39Extended or Code128A or Code128B or Code128C or Code93 or Code93Extended or CodeMSI or CodePostNet or CodeCodabar or CodeEAN8 or CodeEAN13 or CodeUPC_A or CodeUPC_E0 or CodeUPC_E1 or CodeUPC_Supp2 or CodeUPC_Supp5 or CodeEAN128A or CodeEAN128B or CodeEAN128C</barcodeType>. The data is returned as Base64 encoded binary. I have implemented the NSData interface for Base64 by following other posts such as Base64 interface for NSData. I used JMeter to verify the parameters and request syntax. The response returns a reasonable string of data and (hopefully) I have decoded the response and assigned it to the UIImage correctly, but I end up with a blank image.

Here is the SOAP envelope setup along with the commentary from the webservicex.net's website for this API. I have tried dozen's of variations. My suspicion is still around the color and background color parameters. I cannot find details of argument values. I have tried Black, White, black, white, ffffff, 000000, etc.

Also including the initialization for the NSURL:

    soapEnvelope = [[NSMutableString alloc] initWithString:
                          @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];

[soapEnvelope appendString:@"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"];
[soapEnvelope appendString:@"<soap12:Body>"];
[soapEnvelope appendString:@"<GenerateBarCode xmlns=\"http://www.webservicex.net/\">"];
[soapEnvelope appendString:@"<BarCodeParam>"];
[soapEnvelope appendFormat:@"<Height>%d</Height>", 120];
[soapEnvelope appendFormat:@"<Width>%d</Width>", 120];
[soapEnvelope appendFormat:@"<Angle>%d</Angle>", 0];
[soapEnvelope appendFormat:@"<Ratio>%d</Ratio>", 1];
[soapEnvelope appendFormat:@"<Module>%d</Module>", 1];
[soapEnvelope appendFormat:@"<Left>%d</Left>", 20];
[soapEnvelope appendFormat:@"<Top>%d</Top>", 20];
[soapEnvelope appendFormat:@"<CheckSum>%s</CheckSum>", "true"];
[soapEnvelope appendFormat:@"<FontName>%@</FontName>", @"Helvetica"];
[soapEnvelope appendFormat:@"<BarColor>%@</BarColor>", @"yellow"];
[soapEnvelope appendFormat:@"<BGColor>%@</BGColor>", @"black"];
[soapEnvelope appendFormat:@"<FontSize>%f</FontSize>", 10.0f];
[soapEnvelope appendFormat:@"<barcodeOption>%@</barcodeOption>", @"Code"];
[soapEnvelope appendFormat:@"<barcodeType>%@</barcodeType>", @"Code39"];
[soapEnvelope appendFormat:@"<checkSumMethod>%@</checkSumMethod>", @"None"];
[soapEnvelope appendFormat:@"<showTextPosition>%@</showTextPosition>", @"BottomCenter"];
[soapEnvelope appendFormat:@"<BarCodeImageFormat>%@</BarCodeImageFormat>", @"PNG"];
[soapEnvelope appendFormat:@"<BarCodeText>%@</BarCodeText>", [dictArgs objectForKey:@"barcodetext"] ];
[soapEnvelope appendString:@"</BarCodeParam>"];
[soapEnvelope appendString:@"</GenerateBarCode>"];
[soapEnvelope appendString:@"</soap12:Body>"];
[soapEnvelope appendString:@"</soap12:Envelope>"];
/*
 POST /genericbarcode.asmx HTTP/1.1
 Host: www.webservicex.net
 Content-Type: application/soap+xml; charset=utf-8
 Content-Length: length

 <?xml version="1.0" encoding="utf-8"?>
 <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
 <soap12:Body>
 <GenerateBarCode xmlns="http://www.webservicex.net/">
 <BarCodeParam>
 <Height>int</Height>
 <Width>int</Width>
 <Angle>int</Angle>
 <Ratio>int</Ratio>
 <Module>int</Module>
 <Left>int</Left>
 <Top>int</Top>
 <CheckSum>boolean</CheckSum>
 <FontName>string</FontName>
 <BarColor>string</BarColor>
 <BGColor>string</BGColor>
 <FontSize>float</FontSize>
 <barcodeOption>None or Code or Typ or Both</barcodeOption>
 <barcodeType>Code_2_5_interleaved or Code_2_5_industrial or Code_2_5_matrix or Code39 or Code39Extended or Code128A or Code128B or Code128C or Code93 or Code93Extended or CodeMSI or CodePostNet or CodeCodabar or CodeEAN8 or CodeEAN13 or CodeUPC_A or CodeUPC_E0 or CodeUPC_E1 or CodeUPC_Supp2 or CodeUPC_Supp5 or CodeEAN128A or CodeEAN128B or CodeEAN128C</barcodeType>
 <checkSumMethod>None or Modulo10</checkSumMethod>
 <showTextPosition>TopLeft or TopRight or TopCenter or BottomLeft or BottomRight or BottomCenter</showTextPosition>
 <BarCodeImageFormat>BMP or EMF or EXIF or GIF or ICON or JPEG or MemoryBMP or PNG or TIFF or WMF</BarCodeImageFormat>
 </BarCodeParam>
 <BarCodeText>string</BarCodeText>
 </GenerateBarCode>
 </soap12:Body>
 </soap12:Envelope>     
*/

// ref: for example, http://www.webservicex.net/genericbarcode.asmx?WSDL
urlRequest = [[NSURL alloc] initWithScheme:@"http" host:@"www.webservicex.net" 
                                      path:@"/genericbarcode.asmx?op=GenerateBarCode"];

Here is the snippet surrounding the final stage of decoding and assignment:

NSURLRequest *urlThread = (NSMutableURLRequest*) object;

byteImageBarcode = [[NSMutableData alloc] init];
[byteImageBarcode setLength:0];
[byteImageBarcode appendData:
 [NSURLConnection sendSynchronousRequest:urlThread returningResponse:&response error:&error]];

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:byteImageBarcode];

.
.
.

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    NSLog(@"%s [%@]", __FUNCTION__, string);

    NSLog(@"\n\n%s\n\n", elementGenerateBarCodeResult ? "Convert Image Data" : "hmmm ... element not GenerateBarCodeResult");

    if (elementGenerateBarCodeResult) {
        NSData *nsdata = [NSData dataWithBase64EncodedString: string];

        NSLog(@"%s [%@]", __FUNCTION__, nsdata);

        imageBarcode = [[UIImage alloc] initWithData: nsdata];

    }

}

Following is a dump (in the debugger console) of the NSData that is the converted image binary. Now that I fixed the "append" in the foundCharacters, the image is no longer white, it is the color of my View's background. Does that mean I have a completely transparent image or an image that is so small that it does not display ?! Can someone decode this to determine if it is a valid PNG binary? (NOTE: I found this cool conversion tool: enter link description here And I noticed that when I put the following data into the translator, the translation has the value (hex)89 followed by PNG cr-lf. I think I have it correctly converted.

But my UIImage does not render. The UIImageView's size reports as width x height = (240.00, 240.00).

    Printing description of byteImageBarcode:
<89504e47 0d0a1a0a 0000000d 49484452 000000f0 000000f0 08060000 003e55e9 92000000 01735247 4200aece 1ce90000 00046741 4d410000 b18f0bfc 61050000 00206348 524d0000 7a260000 80840000 fa000000 80e80000 75300000 ea600000 3a980000 17709cba 513c0000 069e4944 4154785e edd6090d c0401003 b12b7fd0 fd588ce2 4310391b b5d7fdbe e31120d0 14f806ec 1120d014 38cdd852 1320f0ff 3d632040 a02b60c0 ddee2427 e00bec06 0894057c 81cbedc9 3e2f60c0 f32700a0 2c60c0e5 f6649f17 30e0f913 00501630 e0727bb2 cf0b18f0 fc090028 0b1870b9 3dd9e705 0c78fe04 0094050c b8dc9eec f302063c 7f0200ca 02065c6e 4ff67901 039e3f01 00650103 2eb727fb bc8001cf 9f0080b2 800197db 937d5ec0 80e74f00 4059c080 cbedc93e 2f60c0f3 2700a02c 60c0e5f6 649f1730 e0f91300 501630e0 727bb2cf 0b18f0fc 0900280b 1870b93d d9e7050c 78fe0400 94050cb8 dc9eecf3 02063c7f 0200ca02 065c6e4f f6790103 9e3f0100 6501032e b727fbbc 8001cf9f 0080b280 0197db93 7d5ec080 e74f0040 59c080cb edc93e2f 60c0f327 00a02c60 c0e5f664 9f1730e0 f9130050 1630e072 7bb2cf0b 18f0fc09 00280b18 70b93dd9 e7050c78 fe040094 050cb8dc 9eecf302 063c7f02 00ca0206 5c6e4ff6 7901039e 3f010065 01032eb7 27fbbc80 01cf9f00 80b28001 97db937d 5ec080e7 4f004059 c080cbed c93e2f60 c0f32700 a02c60c0 e5f6649f 1730e0f9 13005016 30e0727b b2cf0b18 f0fc0900 280b1870 b93dd9e7 050c78fe 04009405 0cb8dc9e ecf30206 3c7f0200 ca02065c 6e4ff679 01039e3f 01006501 032eb727 fbbc8001 cf9f0080 b2800197 db937d5e c080e74f 004059c0 80cbedc9 3e2f60c0 f32700a0 2c60c0e5 f6649f17 30e0f913 00501630 e0727bb2 cf0b18f0 fc090028 0b1870b9 3dd9e705 0c78fe04 0094050c b8dc9eec f302063c 7f0200ca 02065c6e 4ff67901 039e3f01 00650103 2eb727fb bc8001cf 9f0080b2 800197db 937d5ec0 80e74f00 4059c080 cbedc93e 2f60c0f3 2700a02c 60c0e5f6 649f1730 e0f91300 501630e0 727bb2cf 0b18f0fc 0900280b 1870b93d d9e7050c 78fe0400 94050cb8 dc9eecf3 02063c7f 0200ca02 065c6e4f f6790103 9e3f0100 6501032e b727fbbc 8001cf9f 0080b280 0197db93 7d5ec080 e74f0040 59c080cb edc93e2f

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2024-11-16 16:17:46

尝试获取并打印一些图像数据,看看是否合理。例如[imageBarcode 尺寸].width 和[imageBarcode 尺寸].height。

无论哪种情况,您都需要一个 UIImageView 来附加条形码图像以供显示。我怀疑你知道这一点,但问题出在其他地方。

Try to get and print some image data to see if it's reasonable. For example [imageBarcode size].width and [imageBarcode size].height.

In either case, you need a UIImageView into which to attach the barcode image for it to display. I suspect you know that though and the problem is somewhere else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文