遇到截屏拼接二维码,并分享的要求,

1,首先二维码生成

//生成二维码

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

// 2.过滤器恢复默认设置

[filter setDefaults];

// 3.给过滤器添加数据(正则表达式/帐号和密码) -- 通过KVC设置过滤器,只能设置NSData类型

NSString *dataString = @"http://www.baidu.com";

NSData *data = [dataString dataUsingEncoding:NSUTF8StringEncoding];

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

// 4.获取输出的二维码

CIImage *outputImage = [filter outputImage];

// 5.显示二维码

UIImageView *erweimaImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];

2 截屏,并保存一下

CGRect rect = CGRectMake(0, 0, XHW_W , XHW_H);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

[self.view.layer renderInContext:context];

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

_mergeImage = img;

[_TopimageView setImage:img];


3,拼接截屏的图片和二维码


//合并多张图片(不缩小,原大小)

- (UIImage *)composeWithHeader:(UIImage *)header footer:(UIImage *)footer{

CGSize size = CGSizeMake(header.size.width, (header.size.height)  + (88));

//UIGraphicsBeginImageContextWithOptions(<#CGSize size#>, BOOL opaque, CGFloat scale)

UIGraphicsBeginImageContextWithOptions(size, YES, 0.0);

CGContextRef context = UIGraphicsGetCurrentContext();

//CGContextSetFillColorWithColor(<#CGContextRef  _Nullable c#>, <#CGColorRef  _Nullable color#>)

CGContextSetFillColorWithColor(context,  [UIColor colorWithPatternImage:[UIImage imageNamed:@"WechatIMG1 2"]].CGColor);//在这段上下文中获取到颜色UIColor

CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height));

//用这个颜色填充这个上下文

[header drawInRect:CGRectMake(0, 0, header.size.width, header.size.height)];

[footer drawInRect:CGRectMake(0,  header.size.height - 150 , (100), (100))];

//[self drawText:context frame:CGRectMake(0, 0, size.width, size.height)];

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

你可能感兴趣的:(遇到截屏拼接二维码,并分享的要求,)