-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
232 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,10 @@ | |
|
||
/** | ||
* 生成条形码/二维码示例 | ||
* @author Jenly <a href="mailto:[email protected]">Jenly</a> | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
public class CodeActivity extends AppCompatActivity { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,10 @@ import com.king.zxing.analyze.QRCodeAnalyzer | |
|
||
/** | ||
* 扫二维码全屏识别示例 | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
class FullScreenQRCodeScanActivity : BarcodeCameraScanActivity() { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import android.graphics.Bitmap; | ||
import android.os.Bundle; | ||
import android.provider.MediaStore; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.Toast; | ||
|
@@ -28,17 +29,21 @@ | |
import androidx.core.app.ActivityOptionsCompat; | ||
|
||
import com.king.camera.scan.CameraScan; | ||
import com.king.camera.scan.util.LogUtils; | ||
import com.king.zxing.util.CodeUtils; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
/** | ||
* 扫码示例 | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = "MainActivity"; | ||
public static final String KEY_TITLE = "key_title"; | ||
public static final String KEY_IS_QR_CODE = "key_code"; | ||
|
||
|
@@ -88,8 +93,10 @@ private void parsePhoto(Intent data) { | |
//异步解析 | ||
asyncThread(() -> { | ||
final String result = CodeUtils.parseCode(bitmap); | ||
// 如果只需识别二维码,建议使用:parseQRCode;(因为识别的格式越明确,误识别率越低。) | ||
// final String result = CodeUtils.parseQRCode(bitmap); | ||
runOnUiThread(() -> { | ||
LogUtils.d("result:" + result); | ||
Log.d(TAG, "result:" + result); | ||
showToast(result); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,10 @@ import com.king.zxing.analyze.MultiFormatAnalyzer | |
|
||
/** | ||
* 连续扫码(识别多种格式)示例 | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
class MultiFormatScanActivity : BarcodeCameraScanActivity() { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,18 @@ | |
import com.king.zxing.DecodeConfig; | ||
import com.king.zxing.DecodeFormatManager; | ||
import com.king.zxing.BarcodeCameraScanActivity; | ||
import com.king.zxing.analyze.MultiFormatAnalyzer; | ||
import com.king.zxing.analyze.QRCodeAnalyzer; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
/** | ||
* 扫二维码识别示例 | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
public class QRCodeScanActivity extends BarcodeCameraScanActivity { | ||
|
||
|
@@ -38,8 +42,8 @@ public Analyzer<Result> createAnalyzer() { | |
.setAreaRectRatio(0.8f)//设置识别区域比例,默认0.8,设置的比例最终会在预览区域裁剪基于此比例的一个矩形进行扫码识别 | ||
.setAreaRectVerticalOffset(0)//设置识别区域垂直方向偏移量,默认为0,为0表示居中,可以为负数 | ||
.setAreaRectHorizontalOffset(0);//设置识别区域水平方向偏移量,默认为0,为0表示居中,可以为负数 | ||
// BarcodeCameraScanActivity默认使用的MultiFormatAnalyzer,这里可以改为使用QRCodeAnalyzer | ||
return new QRCodeAnalyzer(decodeConfig); | ||
// BarcodeCameraScanActivity默认使用的MultiFormatAnalyzer,这里也可以改为使用QRCodeAnalyzer | ||
return new MultiFormatAnalyzer(decodeConfig); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
* 通过继承 {@link BarcodeCameraScanActivity}或{@link BarcodeCameraScanFragment}可快速实现扫码识别 | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
public abstract class BarcodeCameraScanActivity extends BaseCameraScanActivity<Result> { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
* 通过继承 {@link BarcodeCameraScanActivity}或{@link BarcodeCameraScanFragment}可快速实现扫码识别 | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
public abstract class BarcodeCameraScanFragment extends BaseCameraScanFragment<Result> { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,16 @@ | |
|
||
import android.graphics.Rect; | ||
|
||
import androidx.annotation.FloatRange; | ||
import androidx.annotation.NonNull; | ||
|
||
import com.google.zxing.BarcodeFormat; | ||
import com.google.zxing.DecodeHintType; | ||
import com.google.zxing.common.GlobalHistogramBinarizer; | ||
import com.google.zxing.common.HybridBinarizer; | ||
|
||
import java.util.Map; | ||
|
||
import androidx.annotation.FloatRange; | ||
|
||
/** | ||
* 解码配置:主要用于在扫码识别时,提供一些配置,便于扩展。通过配置可决定内置分析器的能力,从而间接的控制并简化扫码识别的流程 | ||
* <p></> | ||
|
@@ -25,7 +26,6 @@ | |
* {@link DecodeFormatManager#DEFAULT_HINTS} | ||
* <p> | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* 如果不满足您也可以通过{@link DecodeFormatManager#createDecodeHints(BarcodeFormat...)}自己配置支持的格式 | ||
* | ||
|
@@ -38,7 +38,11 @@ | |
* 因为{@link androidx.camera.view.PreviewView}的预览区域是经过裁剪的,所以这里的区域并不是用户所能预览到的区域,而是指Camera预览的真实区域, | ||
* <p> | ||
* 即判定区域分析的优先级顺序为:{@link #setFullAreaScan(boolean)} -> {@link #setAnalyzeAreaRect(Rect)} -> {@link #setAreaRectRatio(float)} | ||
* <p></> | ||
* <p> | ||
* | ||
* @author <a href="mailto:[email protected]">Jenly</a> | ||
* <p> | ||
* <a href="https://github.com/jenly1314">Follow me</a> | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class DecodeConfig { | ||
|
@@ -325,7 +329,7 @@ public int getAreaRectVerticalOffset() { | |
/** | ||
* 设置识别区域垂直方向偏移量,支持负数,大于0时,居中心向下偏移,小于0时,居中心向上偏移 | ||
* | ||
* @param areaRectVerticalOffset | ||
* @param areaRectVerticalOffset 识别区域垂直方向偏移量 | ||
* @return {@link DecodeConfig} | ||
*/ | ||
public DecodeConfig setAreaRectVerticalOffset(int areaRectVerticalOffset) { | ||
|
@@ -345,14 +349,15 @@ public int getAreaRectHorizontalOffset() { | |
/** | ||
* 设置识别区域水平方向偏移量,支持负数,大于0时,居中心向右偏移,小于0时,居中心向左偏移 | ||
* | ||
* @param areaRectHorizontalOffset | ||
* @param areaRectHorizontalOffset 识别区域水平方向偏移量 | ||
* @return {@link DecodeConfig} | ||
*/ | ||
public DecodeConfig setAreaRectHorizontalOffset(int areaRectHorizontalOffset) { | ||
this.areaRectHorizontalOffset = areaRectHorizontalOffset; | ||
return this; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String toString() { | ||
return "DecodeConfig{" + | ||
|
Oops, something went wrong.