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

| 我在webservicesx.net上找到了一个条形码生成器,该条形码生成器使用SOAP接口请求条形码图像。它支持多种格式“ 0”。数据以Base64编码的二进制形式返回。我已经按照其他帖子(例如NSData的Base64接口)实现了Base64的NSData接口。我使用JMeter来验证参数和请求语法。响应返回一个合理的数据字符串,并且(希望如此)我已经解码了响应并将其正确分配给UIImage,但是最终得到的是空白图像。 这是SOAP信封设置以及webservicex.net网站上针对此API的注释。我尝试了十几种。我仍然怀疑颜色和背景颜色参数。我找不到参数值的详细信息。我尝试了黑色,白色,黑色,白色,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中修复了\“ append \”,图像不再是白色,而是视图背景的颜色。这是否意味着我具有完全透明的图像或太小的图像而无法显示?有人可以解码以确定它是否是有效的PNG二进制文件吗? (注意:我找到了这个很酷的转换工具:在此处输入链接描述,我注意到当我将以下数据放入翻译器时,翻译的值是(hex)89,后跟PNG cr-lf。我认为我正确转换。 但是我的UIImage无法渲染。 UIImageView的大小报告为
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
    
已邀请:
尝试获取并打印一些图像数据,看是否合理。例如[imageBarcode size] .width和[imageBarcode size] .height。 无论哪种情况,都需要一个UIImageView来附加条形码图像以使其显示在其中。我怀疑您知道,但是问题出在其他地方。     

要回复问题请先登录注册