xcode iOS中各种条码阅读器免费SDK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15779477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Various barcode reader free SDK in iOS
提问by xrnd
I am making a barcode reader app which is free. I am looking for free SDK to decode Datamatrix,QR,Aztec,UPC,EAN barcodes. I have implemented ZBar SDK as per now. Which detects QR,UPC and EAN successfully. I tested This link
我正在制作一个免费的条形码阅读器应用程序。我正在寻找免费的 SDK 来解码 Datamatrix、QR、Aztec、UPC、EAN 条码。我现在已经实现了 ZBar SDK。成功检测到 QR、UPC 和 EAN。我测试了这个链接
But none of these are able to detect Aztec properly. With Data Matrix,UPC,EAN and QR i found Redlaser very effective but now its not free.
但是这些都无法正确检测 Aztec。使用 Data Matrix、UPC、EAN 和 QR,我发现 Redlaser 非常有效,但现在它不是免费的。
Now, is there any free SDK available to detect all four barcodes without paying as i want to keep my app free on app store.
现在,是否有任何免费的 SDK 可用于检测所有四个条形码而无需付费,因为我想在应用程序商店中免费保留我的应用程序。
Please suggest
请建议
P.S I want compatibility of scanner with latest iOS available.
PS 我希望扫描仪与可用的最新 iOS 兼容。
回答by Edwin Vermeer
With some work you could do this using zint. See https://github.com/samlown/zint/blob/master/backend/aztec.cI have used this in an app. Sorry, I am not allowed to share more code than this: include the barcode, aztec, common, font, gs1, rs and bmp classes Then put the code below in a seperate class
通过一些工作,您可以使用 zint 来做到这一点。请参阅https://github.com/samlown/zint/blob/master/backend/aztec.c我在一个应用程序中使用过它。抱歉,我不允许分享比这更多的代码:包括条形码、aztec、common、font、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;
}
回答by Ganapathy
You scan customize the ZBar Scanner like set some more Symbology like this
您扫描自定义 ZBar 扫描仪,就像设置更多这样的符号一样
-(void)scanProductBarCode
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
reader.supportedOrientationsMask = ZBarOrientationMaskLandscape;
else
reader.supportedOrientationsMask = ZBarOrientationMaskPortrait;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_UPCA config: ZBAR_CFG_ENABLE to: 1];
[scanner setSymbology: ZBAR_CODE39 config: ZBAR_CFG_ADD_CHECK to: 0];
[scanner setSymbology:ZBAR_QRCODE config:ZBAR_CFG_ADD_CHECK to:1];
[scanner setSymbology:ZBAR_EAN13 config:ZBAR_CFG_ADD_CHECK to:1];
[self presentModalViewController:reader animated:YES];
}
回答by Nick Toumpelis
These days you can use AVFoundation for scanning barcodes, and has support for all the barcode types you mentioned in your question.
如今,您可以使用 AVFoundation 来扫描条形码,并且支持您在问题中提到的所有条形码类型。
A quick tutorial: Building a Barcode and QR Code Reader in Swift 3 and Xcode 8