Re: [問題] zbarSDK的問題(QR Code)
※ 引述《fightword (呼啦啦~)》之銘言:
: 請教一下有用過zbarSDK的大大
: zbarsdk作QRCODE時,
: 掃瞄可以設範圍嗎?
: 就是
: -----------------
: |
: |
: --------- |
: | 掃瞄 | |
: | 區域 | |
: | | |
: --------- |
: |
: camera |
: View |
: ----------------
: 整個View是相機的畫面
: 然後只有掃瞄區域偵測到的才會有反應
: 或有其他library(free)可以推薦的 謝謝
一年多前有做過類似的功能,如有記錯的地方還請海涵。
首先,我假設你是使用ZBarReaderView來做cameraView。
在ZBarReaderView裡有個property叫做scanCrop,就是用來設定掃瞄的區域。
見zbar文件
http://zbar.sourceforge.net/iphone/sdkdoc/ZBarReaderView.html#scanCrop__CGRect
CGRect scanCrop
The region of the video image that will be scanned,
in normalized image coordinates.
Note that the video image is in landscape mode (default {{0, 0}, {1, 1}})
這個屬性必須填入scanView相對於ZBarReaderView的比例,而且是以landscape mode
下去計算。
根據我之前在網路上找到的資料,在landscape orientation下可以這樣使用
CGFloat x,y,width,height;
x = scanView.frame.origin.x / readerView.bounds.size.width;
y = scanView.frame.origin.y / readerView.bounds.size.height;
width = scanView.frame.size.width / readerView.bounds.size.width;
height = scanView.frame.size.height / readerView.bounds.size.height;
readerView.scanCrop = CGRectMake(x, y, width, height);
在portrait orientation下,由於zbar還是會以lanscape orientation的比例去算
所以要自己做轉換
CGFloat x = CGRectGetX(scanView.frame);
CGFloat y = CGRectGetY(scanView.frame);
CGFloat width = CGRectGetWidth(scanView.frame);
CGFloat height = CGRectGetHeight(scanView.frame);
landscapeX = y / readerView.bounds.size.width;
landscapeY = 1 - (x+width) / readerView.bounds.size.height;
landscapeWidth = height / readerView.bounds.size.width;
landscapeHeight = width / readerView.bounds.size.height;
readerView.scanCrop =
CGRectMake(landscapeX, landscapeY, landscapeWidth, landscapeHeight);
至於為什麼這樣轉,其實拿紙跟筆畫個圖,想辦法把portrait的scanView frame轉成
lanscape的scanView frame就懂了。
參考資料
zbar usage
http://www.ikoding.com/using-zbarsdk-in-ios/
landscape
http://goo.gl/a1yq9u
portrait,這一篇x, y 是對的,但height與width計算方式可能有誤,見下面連結
http://goo.gl/aq85Vn
看這篇spadix的回應,作者只有把height跟width交換
http://sourceforge.net/p/zbar/support-requests/34/
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.68.117.86
※ 編輯: vampirewalk 來自: 219.68.117.86 (09/28 14:14)
※ 編輯: vampirewalk 來自: 219.68.117.86 (09/28 14:15)
※ 編輯: vampirewalk 來自: 219.68.117.86 (09/28 14:16)
※ 編輯: vampirewalk 來自: 219.68.117.86 (09/28 14:17)
※ 編輯: vampirewalk 來自: 219.68.117.86 (09/28 14:19)
※ 編輯: vampirewalk 來自: 219.68.117.86 (09/28 14:19)
※ 編輯: vampirewalk 來自: 219.68.117.86 (09/28 14:20)
推
09/28 18:03, , 1F
09/28 18:03, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章