zoukankan      html  css  js  c++  java
  • iOS开发——生成条形码,二维码

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        self.imageView.image = [self generateBarCode:@"1524829417" 60 height:60];

        

        self.imageView2.image = [self generateQRCode:@"1524829417" 60 height:60];

    }

    - (UIImage *)generateBarCode:(NSString *)code (CGFloat)width height:(CGFloat)height {

        // 生成条形码图片

        CIImage *barcodeImage;

        NSData *data = [code dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:false];

        CIFilter *filter = [CIFilter filterWithName:@"CICode128BarcodeGenerator"];

        

        [filter setValue:data forKey:@"inputMessage"];

        barcodeImage = [filter outputImage];

        

        // 消除模糊

        CGFloat scaleX = width / barcodeImage.extent.size.width; // extent 返回图片的frame

        CGFloat scaleY = height / barcodeImage.extent.size.height;

        CIImage *transformedImage = [barcodeImage imageByApplyingTransform:CGAffineTransformScale(CGAffineTransformIdentity, scaleX, scaleY)];

        

        return [UIImage imageWithCIImage:transformedImage];

    }

    - (UIImage *)generateQRCode:(NSString *)code (CGFloat)width height:(CGFloat)height {

        

        // 生成二维码图片

        CIImage *qrcodeImage;

        NSData *data = [code dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:false];

        CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];

        

        [filter setValue:data forKey:@"inputMessage"];

        [filter setValue:@"H" forKey:@"inputCorrectionLevel"];

        qrcodeImage = [filter outputImage];

        

        // 消除模糊

        CGFloat scaleX = width / qrcodeImage.extent.size.width; // extent 返回图片的frame

        CGFloat scaleY = height / qrcodeImage.extent.size.height;

        CIImage *transformedImage = [qrcodeImage imageByApplyingTransform:CGAffineTransformScale(CGAffineTransformIdentity, scaleX, scaleY)];

        

        return [UIImage imageWithCIImage:transformedImage];

    }

  • 相关阅读:
    HTML 图片文字滚动
    Request.QueryString的用法
    细线表格的制作
    photoshop的小小快捷键
    制作首页
    css
    编写BLL层
    完成新闻表操作类
    编写剩下的存储过程
    重构SQLHelper2
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/4801555.html
Copyright © 2011-2022 走看看