LBXScan
LBXScan copied to clipboard
使用iOS原生框架读取相册中的二维码,识别出现问题
把从相册中的照片缩放到屏幕大小,就可以识别成功了,建议作者改进一下。
(对不住作者了,动了你框架中的代码)
我知道是这个原因导致的失败,也是在翻阅SGQRCode的代码知道的。
-
(UIImage *)imageSizeWithScreenImage:(UIImage *)image { CGFloat imageWidth = image.size.width; CGFloat imageHeight = image.size.height; CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if (imageWidth <= screenWidth && imageHeight <= screenHeight) { return image; }
CGFloat max = MAX(imageWidth, imageHeight); CGFloat scale = max / (screenHeight * 2.0);
CGSize size = CGSizeMake(imageWidth / scale, imageHeight / scale); UIGraphicsBeginImageContext(size); [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
return newImage; }
谢谢提供代码,欢迎加入 QQ交流群: 522806629
改了,依然在崩溃,不知道原因。