通過一些工作,你可以使用zint來做到這一點。請參閱https://github.com/samlown/zint/blob/master/backend/aztec.c 我已經在應用程序中使用過此功能。對不起,我不是不能超過這個分享更多的代碼: 包括條碼,阿茲臺克,常見,字體,GS1,RS和BMP類 然後把下面的代碼在一個單獨的類
void dataProviderReleased (void *info, const void *data, size_t size) {
struct barcode_symbol *my_symbol = info;
Barcode_Delete(my_symbol);
}
+ (UIImage *)aztecBarcodeImageFromString:(NSString *)s scale:(CGFloat)scale {
UIImage *image = nil;
int errorCode = 0;
struct barcode_symbol *my_symbol;
if (s == nil) {
return nil;
}
unsigned char *unicodeCharPtr = (unsigned char *)[s cStringUsingEncoding:NSUTF8StringEncoding];
LogInfo(@"Creating barcode image for string: %@", s);
my_symbol = Barcode_Create();
my_symbol->output_options = 0;
//my_symbol->output_options = BARCODE_BOX; //For a box around the bar code
my_symbol->scale = scale;
my_symbol->symbology = BARCODE_AZTEC;
my_symbol->input_mode = UNICODE_MODE;
errorCode = Barcode_Encode(my_symbol, unicodeCharPtr, 0);
if (errorCode == 0) {
errorCode = Barcode_Buffer(my_symbol, 0);
if (errorCode == 0) {
int numberOfComponents = 3;
long imgSizePerRow = numberOfComponents * my_symbol->bitmap_width;
long imgSize = imgSizePerRow * my_symbol->bitmap_height;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//The dataProviderReleased method is responsible for deallocating the ZBarCode with the corresponding image data
CGDataProviderRef providerRef = CGDataProviderCreateWithData(my_symbol, my_symbol->bitmap, imgSize, dataProviderReleased);
CGImageRef imageRef = CGImageCreate(my_symbol->bitmap_width, my_symbol->bitmap_height, 8, numberOfComponents * 8,
imgSizePerRow, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaNone,
providerRef, NULL, NO, kCGRenderingIntentDefault);
image = [UIImage imageWithCGImage:imageRef];
CGColorSpaceRelease(colorSpace);
CGDataProviderRelease(providerRef);
CGImageRelease(imageRef);
} else {
LogWarn(@"Could not buffer barcode, error=%d", errorCode);
Barcode_Delete(my_symbol);
}
} else {
LogWarn(@"Could not encode barcode, error=%d", errorCode);
Barcode_Delete(my_symbol);
}
return image;
}
https://code.google.com/p/zxing/斑馬線? – borrrden
對不起,忘記提及它說的是Android/Java(但它有一個iOS版本的源碼) – borrrden
我同意它的一個很好的代碼,但它沒有掃描阿茲特克鱈魚,那是我之前陷入困境的地方。爲了休息一切,它的作品就像一個魅力,但我發現阿茲臺克人很難找到它。 – xrnd