사이트 주소가 QR코드 그림으로 바뀌다

2019 단어
-(void)createqQrCode

{
    
    // 
    
    CIFilter *filter=[CIFilter filterWithName:@"CIQRCodeGenerator"];
    
    // 
    
    [filter setDefaults];
    
    // NSData
    
    NSData *data=[@"https://www.baidu.com" dataUsingEncoding:NSUTF8StringEncoding];
    
    // KVO inputmessage 
    
    [filter setValue:data forKey:@"inputMessage"];
    
    // 
    
    CIImage *outputImage=[filter outputImage];
    
    // CIImage UIImage, 
    
    _imgView.image=[self createNonInterpolatedUIImageFormCIImage:outputImage withSize:100.0];
    
    // , ImageView Layer 
    
    _imgView.layer.shadowOffset=CGSizeMake(0, 0.5);// 
    
    _imgView.layer.shadowRadius=1;// 
    
    _imgView.layer.shadowColor=[UIColor blackColor].CGColor;// 
    _imgView.layer.shadowOpacity=0.3;
    

}

QR코드 크기 변경

- (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size {
    
    CGRect extent = CGRectIntegral(image.extent);
    
    CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
    
    //  bitmap;
    
    size_t width = CGRectGetWidth(extent) * scale;
    
    size_t height = CGRectGetHeight(extent) * scale;
    
    CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
    
    CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
    
    CIContext *context = [CIContext contextWithOptions:nil];
    
    CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
    
    CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
    
    CGContextScaleCTM(bitmapRef, scale, scale);
    
    CGContextDrawImage(bitmapRef, extent, bitmapImage);
    
    //  bitmap 
    
    CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
    
    CGContextRelease(bitmapRef);
    
    CGImageRelease(bitmapImage);
    
    return [UIImage imageWithCGImage:scaledImage];
    
}

좋은 웹페이지 즐겨찾기