【发布时间】:2011-08-11 04:08:00
【问题描述】:
我想获取一个数字字符串并生成一个可以被任何扫描仪读取的简单条形码。
我已经可以使用相机读取条形码,但现在我想生成条形码。
有没有人知道可以让我这样做的 sdk、资源或代码片段?
谢谢
【问题讨论】:
-
查看这个关于 EAN13 的答案stackoverflow.com/a/36875393/3472073
我想获取一个数字字符串并生成一个可以被任何扫描仪读取的简单条形码。
我已经可以使用相机读取条形码,但现在我想生成条形码。
有没有人知道可以让我这样做的 sdk、资源或代码片段?
谢谢
【问题讨论】:
做到这一点的唯一免费库是Cocoa-Touch-Barcodes,它是cocoabarcodes 的一个分支。如果你正在考虑商业图书馆,有一个叫iPhone Barcode Generator。
更新检查ZXing的这个objective-c端口:https://github.com/TheLevelUp/ZXingObjC
【讨论】:
在您的头文件中包含:#import "NKDBarcodeFramework.h",并将这些行放在您的 init 函数中。
barcode = [NKDExtendedCode39Barcode alloc];
barcode = [barcode initWithContent:@"1234567890123" printsCaption:0];
[barcode calculateWidth];
NSLog(@"%@",[barcode description]);
theImage = [UIImage imageFromBarcode:barcode];
subview = [[UIImageView alloc]initWithFrame:TTScreenBounds()];
[subview setImage:theImage];
[self addSubview:subview];
self.frame = self.bounds;
玩得开心:-)
【讨论】:
条码种类太多了
每种条码类型都有很多子类型,每种都有自己的用途。
我解释如何生成 One D 条码类型代码 39 之一
这里我解释了如何使用自定义字体生成条形码
步骤:
1)从here下载自定义字体
2)从下载的zip中附加文件FRE3OF9X.ttf
3) 在 info.plist 和 item 0 中添加键 Fonts provided by application 并赋予 FRE3OF9X.ttf 作为值
4)试试下面的代码sn-p
UIFont *fntCode39=[UIFont fontWithName:@"Free3of9Extended" size:30.0];
UILabel *lblBarCodeTest=[[UILabel alloc]initWithFrame:CGRectMake(0,100,768,30)];
[lblBarCodeTest setBackgroundColor:[UIColor lightGrayColor]];
[lblBarCodeTest setTextAlignment:NSTextAlignmentCenter];
[lblBarCodeTest setFont:fntCode39];
[lblBarCodeTest setText:@"*BarCode3Of9_AKA_Code39-ItsA1DBarcode*"];
[self.view addSubview:lblBarCodeTest];
结果:
【讨论】:
您可以使用 CoreImage 生成条形码图像。 CoreImage 包含 4 个过滤器来生成不同的条形码:CICode128BarcodeGenerator、CIQRCodeGenerator、CIPDF417BarcodeGenerator、CIAztecCodeGenerator。
【讨论】:
我创建了一个用于生成 Code 39 条形码的简单类,只需将一个 .h 和一个 .m 添加到您的项目中,并通过一行代码为您生成带有 code 39 编码数据的 UIImage,例如这个:
UIImage *code39Image = [Code39 code39ImageFromString:@"HELLO CODE39" Width:barcode_width Height:barcode_height];
这里是 github 上的项目链接: [https://github.com/bclin087/Simple-Code39-generator-for-iOS.git]
【讨论】: