Zxing 二维码扫描
Zxing 二维码扫描
kylinhuang 发表于3年前
Zxing 二维码扫描
  • 发表于 3年前
  • 阅读 61
  • 收藏 0
  • 点赞 0
  • 评论 0

【腾讯云】买域名送云解析+SSL证书+建站!>>>   

ZXing---- 开源项目 版本 2015-5-15

github----https://github.com/zxing/zxing 

core ---- ZXingCore_2015_5_15.jar

android_core ---项目中 有所修改 

删除不需要的文件

delete  

---package com.google.zxing.client.android.history; ---历史

---package com.google.zxing.client.android.wifi; 

---com.google.zxing.client.android.clipboard     ----copy

---

modify

--- CaptureActivity  ---Too much to change

--- DecodeHandler decode方法中 

PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);前面

----add 更改宽高

byte[] rotatedData = new byte[data.length];

for (int y = 0; y < height; y++) {

for (int x = 0; x < width; x++)

rotatedData[x * height + height - y - 1] = data[x + y * width];

}

int tmp = width;

width = height;

height = tmp;

data = rotatedData;

---CameraManager getFramingRect方法 ---设置选择区域Rect 

framingRect = new Rect(leftOffset, topOffset, leftOffset + width, topOffset + height);更改

//---change

int width = findDesiredDimensionInRange(screenResolution.x,MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);

int height = findDesiredDimensionInRange(screenResolution.y,MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);

//---Modify

DisplayMetrics metrics = context.getResources().getDisplayMetrics();

int width = (int) (metrics.widthPixels * 0.7);

int height = (int) (width * 0.9);


int leftOffset = (screenResolution.x - width) / 2;

int topOffset = (screenResolution.y - height) / 2;


// add

topOffset = (screenResolution.y - height) / 4;

---CameraManager getFramingRectInPreview方法 --- 计算屏幕的位置

//---change

rect.left = rect.left * cameraResolution.x / screenResolution.x;

rect.right = rect.right * cameraResolution.x /screenResolution.x;

rect.top = rect.top * cameraResolution.y / screenResolution.y;

rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;

//---Modify

rect.left = rect.left * cameraResolution.y / screenResolution.x;

rect.right = rect.right * cameraResolution.y / screenResolution.x;

rect.top = rect.top * cameraResolution.x / screenResolution.y;

rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;

---CameraManager openDriver方法 设置竖屏

theCamera.setPreviewDisplay(holder);之后添加

//add

theCamera.setDisplayOrientation(90);

---CameraConfigurationManager initFromCameraParameters方法

cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution);之前添加

//add

// ------

Point screenResolutionForCamera = new Point();

screenResolutionForCamera.x = screenResolution.x;

screenResolutionForCamera.y = screenResolution.y;

if(screenResolution.x < screenResolution.y) {

screenResolutionForCamera.x = screenResolution.y;

screenResolutionForCamera.y = screenResolution.x;

}

//----



Zxing 连续扫描

1扫描完成添加

if (surfaceHolder != null)

    initCamera(surfaceHolder);

if (handler != null)

    handler.restartPreviewAndDecode(); 

2.initCamera方法是有参数的,可参考onResume方法改为

SurfaceView surfaceView = (SurfaceView)findViewById(R.id.preview_view);;

SurfaceHolder surfaceHolder = surfaceView.getHolder();
initCamera(surfaceHolder);

3.mHandler即为当前Activity中的CaptureActivityHandler

4.restartPreviewAndDecode方法在com.zxing.decoding.CaptureActivityHandler中,要改为public


  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 3
博文 31
码字总数 23836
×
kylinhuang
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: