iPhone barcode image rendering from a webservices (SOAP) generator displays as blank?
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: lengt开发者_JAVA百科h
<?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
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.
精彩评论