|
|
|
//
|
|
|
|
// QRCodeMsgViewController.m
|
|
|
|
// LekangGuard
|
|
|
|
//
|
|
|
|
// Created by ecell on 2022/12/7.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "QRCodeMsgViewController.h"
|
|
|
|
#import <CoreImage/CoreImage.h>
|
|
|
|
|
|
|
|
@interface QRCodeMsgViewController ()
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation QRCodeMsgViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
self.zx_navTitle = GJText(@"二维码");
|
|
|
|
|
|
|
|
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:3 borderWidth:0 borderColor:KKClearColor];
|
|
|
|
[self.view addSubview:bgView];
|
|
|
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight+Adapted(20));
|
|
|
|
make.left.right.equalTo(self.view).inset(Adapted(20));
|
|
|
|
make.height.mas_equalTo(SCREEN_WIDTH+Adapted(40));
|
|
|
|
}];
|
|
|
|
|
|
|
|
UIImageView *qrCodeImg = [UIImageView new];
|
|
|
|
qrCodeImg.image = [self createNonInterpolatedUIImageFormCIImage:APIManager.sharedManager.deviceModel.imei withSize:SCREEN_WIDTH-Adapted(120)];
|
|
|
|
[bgView addSubview:qrCodeImg];
|
|
|
|
[qrCodeImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.right.equalTo(bgView).inset(Adapted(40));
|
|
|
|
make.top.equalTo(bgView).offset(Adapted(25));
|
|
|
|
make.height.mas_equalTo(SCREEN_WIDTH-Adapted(120));
|
|
|
|
}];
|
|
|
|
|
|
|
|
UILabel *imeiLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:KKTextBlackColor text:@"" Radius:0];
|
|
|
|
imeiLabel.text = F(@"IMEI/MEID:%@", APIManager.sharedManager.deviceModel.imei);
|
|
|
|
[bgView addSubview:imeiLabel];
|
|
|
|
[imeiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerX.equalTo(self.view);
|
|
|
|
make.top.equalTo(qrCodeImg.mas_bottom).offset(Adapted(10));
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
|
|
UILabel *tiLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(13) textColor:KKGrey121 text:@"" Radius:0];
|
|
|
|
tiLabel.text = GJText(@"扫一扫二维码,关注我");
|
|
|
|
[bgView addSubview:tiLabel];
|
|
|
|
[tiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.centerX.equalTo(self.view).offset(Adapted(25)+8);
|
|
|
|
make.bottom.equalTo(bgView.mas_bottom).inset(Adapted(45));
|
|
|
|
}];
|
|
|
|
|
|
|
|
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentLeft font:FontADA_(15) textColor:KKTextBlackColor text:@"" Radius:0];
|
|
|
|
nameLabel.text = APIManager.sharedManager.deviceModel.name;
|
|
|
|
[bgView addSubview:nameLabel];
|
|
|
|
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.left.equalTo(tiLabel.mas_left);
|
|
|
|
make.bottom.equalTo(tiLabel.mas_top).inset(10);
|
|
|
|
}];
|
|
|
|
|
|
|
|
UIImageView *iconImg = [UIImageView new];
|
|
|
|
[bgView addSubview:iconImg];
|
|
|
|
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
make.bottom.equalTo(tiLabel.mas_bottom).offset(5);
|
|
|
|
make.right.equalTo(tiLabel.mas_left).inset(8);
|
|
|
|
make.size.mas_equalTo(CGSizeMake(Adapted(50), Adapted(50)));
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (APIManager.sharedManager.deviceModel.image.length <= 0)
|
|
|
|
iconImg.image = ImageName_(APIManager.sharedManager.deviceModel.sex == 2 ? @"icon_head_girl" : @"icon_head_boy");
|
|
|
|
else
|
|
|
|
[iconImg sd_setImageWithURL:[NSURL URLWithString:APIManager.sharedManager.deviceModel.image] placeholderImage:ImageName_(APIManager.sharedManager.deviceModel.sex == 2 ? @"icon_head_girl" : @"icon_head_boy")];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据CIImage生成指定大小的UIImage
|
|
|
|
*
|
|
|
|
* @param imageStr 生成的图片内容
|
|
|
|
* @param size 图片宽度
|
|
|
|
*/
|
|
|
|
- (UIImage *)createNonInterpolatedUIImageFormCIImage:(NSString *)imageStr withSize:(CGFloat)size
|
|
|
|
{
|
|
|
|
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
|
|
|
|
[filter setDefaults];
|
|
|
|
NSData *data = [imageStr dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
[filter setValue:data forKeyPath:@"inputMessage"];
|
|
|
|
//输出图片
|
|
|
|
CIImage *image = [filter outputImage];
|
|
|
|
|
|
|
|
CGRect extent = CGRectIntegral(image.extent);
|
|
|
|
CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
|
|
|
|
|
|
|
|
// 1.创建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);
|
|
|
|
|
|
|
|
// 2.保存bitmap到图片
|
|
|
|
CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
|
|
|
|
CGContextRelease(bitmapRef);
|
|
|
|
CGImageRelease(bitmapImage);
|
|
|
|
|
|
|
|
return [UIImage imageWithCGImage:scaledImage];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
// Get the new view controller using [segue destinationViewController].
|
|
|
|
// Pass the selected object to the new view controller.
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
@end
|