zxing的遠距離才能識別網上說是google做的兼容,修改的方法是修改掃描框,但是很多人吐槽沒用
其實還有一個方法網上也有提到,修改可識別的范圍,微信也是采用了該方法,也就是說二維碼一部分在框外的時候也能識別,但是不知道他的掃描sdk用的是啥。
原理就說這些,接下來講講修改方法:
---------------------------------------------修改聚焦---------------------------------
1、聚焦的修改在AutoFocusManager下的
private static final long AUTO_FOCUS_INTERVAL_MS = 1200L;
默認是2000L也就是2秒吧,我這里改成了1.2秒
---------------------------------------------修改識別域---------------------------------
2、識別區域的修改在
DecodeHandler類的最下邊這個方法
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) { Rect rect = activity.getCropRect(); if (rect == null) { return null; } // Go ahead and assume it's YUV rather than die. return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect .height(), false); }
標紅的4個參數是關鍵,相當於掃描區域的左上右下邊界,而要修改的方式是擴大邊界的范圍,網上的方法是采取全屏:
return new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
這是極端全屏處理,我個人覺得這樣范圍太大,讓人感覺有點怪。個人推薦以下自寫的兩種方式之一:
①讓掃描框成方形,寬度為屏幕寬度
int setInt=(width-rect.width())/2;//調整該數值調整靈敏度
return new PlanarYUVLuminanceSource(data, width, height, 0, rect.top-setInt, width, rect.height()+setInt, false);
②讓掃描框成方形,寬度拓展邊界一半
int setInt=rect.left/2;//調整該數值調整靈敏度
return new PlanarYUVLuminanceSource(data, width, height, rect.left-setInt, rect.top-setInt, rect.width()+setInt, rect.height()+setInt, false);
注意:setint是int類型,其實可以是固定數值,但是如果該值太大會使程序報錯,原因是寬度超過了屏幕分辨率,所以最好不要用固定數值。
好了,分享就到這里,如果你沒有這兩個方法可能sdk的版本不一樣哦,我的是3.3.0版本
-----The End-----
乀(ˉεˉ乀)