iOS条形码

来源:互联网 发布:阿里云 买卖域名规则 编辑:程序博客网 时间:2024/06/10 22:17

1、NKDEAN13Barcode生成条形码。

UIImage *image = [UIImage imageFromBarcode:[[NKDEAN13Barcode alloc] initWithContent:@"6922233623211"]];

    image=[UIImage imageWithCGImage:image.CGImage scale:1.0 orientation:UIImageOrientationDown];

 

    self.imageview.image=image;

此处生成的条形码不能用POS机扫描出来,初步的推测是POS机识别不了这种编码,但手机端都能扫描出来。

2、ZXing 生成条形码,有一个zxing的objc库,用了能扫

  NSError *error = nil;

    ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];

    ZXBitMatrix* result = [writer encode:@"6922233623211"

                                 format:kBarcodeFormatCode128

                                   width:100

                                  height:50

                                  error:&error];

    if (result) {

        CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage ];

        NSLog(@"%@",image);

        UIImage *imag=[UIImage imageWithCGImage:image];

        self.imageview.image=imag;

        

        // This CGImageRef image can be placed in a UIImage, NSImage, or written to a file.

    } else {

        NSString *errorMessage = [error localizedDescription];

 

    }

下载地址:https://github.com/TheLevelUp/ZXingObjC 
0 0