日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【IOS】集成zxing(二维码扫描)

發布時間:2023/12/19 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【IOS】集成zxing(二维码扫描) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

現在zxing已經到了2.2版本,以前的集成方式出了點問題。下面我做出一點修正。
以前的版本的集成方法,參考:http://blog.devtang.com/blog/2012/12/23/use-zxing-library/
按照以前的方式做好后 ?然后就是適配以下現在的版本的修改
1.增加 ??SenTestingKit ?框架 設置為Optional
2.把目錄 iphone/ZXingWidget 下的Tests刪了
3.保留目錄 cpp/core/src 的bigint文件
最后提醒: ?設置查找路徑時應該選擇 ?User Header Search Paths 選項添加查找路徑
保險一點把 ?Always Search User Paths ?選為Yes 這樣就可以了

還有就是要支持ios4.3的話就要設置一下C++Standard Library ?為 ?libstdc++ ?這樣就可以支持4.3的版本?

在線生成二維碼的網站:http://cli.im/ 【拓展:特定區域掃描】
二維碼掃描處理過程:
程序有一個回調方法獲取屏幕圖片,然后進行解析。掃描會不斷獲取屏幕圖片去解析。

自定義掃描區域思路:
只要我們在回調方法里面將獲取的整個屏幕圖片截取某一個區域,就可以實現特定區域掃描功能

1 //回調方法 2 - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection 3 { 4 // 第一步,將sampleBuffer轉成UIImage 5 UIImage *image = [self imageFromSampleBuffer:sampleBuffer]; 6 // 第二步,用Decoder識別圖象 7 [self decodeImage:image]; 8 } 9 10 #pragma mark - 截取圖片 11 12 - (void)cutMapView:(UIView *)theView 13 14 { 15 16 //************** 得到圖片 ******************* 17 18 CGRect rect = theView.frame; //截取圖片大小 19 20 21 22 //開始取圖,參數:截圖圖片大小 23 24 UIGraphicsBeginImageContext(rect.size); 25 26 //截圖層放入上下文中 27 28 [theView.layer renderInContext:UIGraphicsGetCurrentContext()]; 29 30 //從上下文中獲得圖片 31 32 UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 33 34 //結束截圖 35 36 UIGraphicsEndImageContext(); 37 38 39 40 41 42 //************** 存圖片 ******************* 43 44 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 45 46 NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@.png",@"jietu"]]; // 保存文件的名稱 47 48 NSLog(@"filePath = %@",filePath); 49 50 //UIImagePNGRepresentation方法將image對象轉為NSData對象 51 52 //寫入文件中 53 54 BOOL result = [UIImagePNGRepresentation(image)writeToFile: filePath atomically:YES]; 55 56 NSLog(@"result = %d",result); 57 58 59 60 61 62 //*************** 截取小圖 ****************** 63 64 CGRect rect1 = CGRectMake(90, 0, 82, 82);//創建矩形框 65 66 //對圖片進行截取 67 68 UIImage * image2 = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([image CGImage], rect1)]; 69 70 NSString *filePath2 = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@.png",@"jietu2"]]; // 保存文件的名稱 71 72 NSLog(@"filePath = %@",filePath); 73 74 BOOL result2 = [UIImagePNGRepresentation(image2)writeToFile:filePath2 atomically:YES]; 75 76 NSLog(@"result2 = %d",result2); 77 78 79 80 //存入相冊 81 82 //UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 83 84 } 85 86 87 //截取圖片特定區域 88 /** 89 *從圖片中按指定的位置大小截取圖片的一部分 90 * UIImage image 原始的圖片 91 * CGRect rect 要截取的區域 92 */ 93 - (UIImage *)imageFromImage:(UIImage *)image inRect:(CGRect)rect { 94 CGImageRef sourceImageRef = [image CGImage]; 95 CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect); 96 UIImage *newImage = [UIImage imageWithCGImage:newImageRef]; 97 return newImage; 98 }

?

轉載于:https://www.cnblogs.com/DannyApple/p/3940516.html

總結

以上是生活随笔為你收集整理的【IOS】集成zxing(二维码扫描)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。