zxing全屏识别(v2.5.0崩溃问题记录)
自己遇到的问题:/**
* Like {@link #getFramingRect} but coordinates are in terms of the preview frame,
* not UI / screen.
*/
public Rect getFramingRectInPreview() {
if (framingRectInPreview == null) {
Rect rect = new Rect(getFramingRect());
Point cameraResolution = configManager.getCameraResolution();
Point screenResolution = configManager.getScreenResolution();
// 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;
/*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;*/
/***lyl TODO 修改识别区域为全屏***/
//自己傻乎乎的把这里的参数改了以后,在自己跟部分手机上运行,识别,都可以实现全屏识别。但是没想到发版本后,好多手机都出现了崩溃问题。
rect.left = 0;
rect.right =screenResolution.x;
rect.top = 0;
rect.bottom =screenResolution.y;
framingRectInPreview = rect;
}
return framingRectInPreview;
}
出错的位置是:
/**
* A factory method to build the appropriate LuminanceSource object based on the format
* of the preview buffers, as described by Camera.Parameters.
*
* @param data A preview frame.
* @param width The width of the image.
* @param height The height of the image.
* @return A PlanarYUVLuminanceSource instance.
*/
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
Rect rect = getFramingRectInPreview();
int previewFormat = configManager.getPreviewFormat();
String previewFormatString = configManager.getPreviewFormatString();
switch (previewFormat) {
// This is the standard Android format which all devices are REQUIRED to support.
// In theory, it's the only one we should ever care about.
case PixelFormat.YCbCr_420_SP:
// This format has never been seen in the wild, but is compatible as we only care
// about the Y channel, so allow it.
case PixelFormat.YCbCr_422_SP:
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
rect.width(), rect.height());
default:
// The Samsung Moment incorrectly uses this variant instead of the 'sp' version.
// Fortunately, it too has all the Y data up front, so we can read it.
if ("yuv420p".equals(previewFormatString)) {
return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
rect.width(), rect.height());
}
}
throw new IllegalArgumentException("Unsupported picture format: " +
previewFormat + '/' + previewFormatString);
}
public PlanarYUVLuminanceSource(byte[] yuvData, int dataWidth, int dataHeight, int left, int top,
int width, int height) {
super(width, height);
//报错的是这里。
if (left + width > dataWidth || top + height > dataHeight) {
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
} this.yuvData = yuvData;
this.dataWidth = dataWidth;
this.dataHeight = dataHeight;
this.left = left;
this.top = top;
}
原文链接:https://blog.csdn.net/yu_duan_hun/article/details/79388195
1.删除bundle传bitmap的部分直接改为全屏识别
(1)全屏扫样式更改
CameraManager.java
需要更改buildLuminanceSource()方法:
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
return new PlanarYUVLuminanceSource(data, width, height, 0, 0,
width, height);
}
ViewfinderView.java
需要更改onDraw():
public void onDraw(Canvas canvas) {
postInvalidateDelayed(ANIMATION_DELAY, 0, 0,
getWidth(), getHeight());
}
(2)去掉传递图片(一般只需要扫码的条码号或者网址,扫码图片本身我们不关心,如果需要这部分需要对这个图片进行压缩处理,不然会出错)
MipActivityCapture.java
这里需要删掉handleDecode里面的bundle.putParcelable("bitmap", barcode);,barcode这个参数也可以不用传递了。
相应的在CaptureActivityHandler.java的handleMessage中只需要传递msg.obj,下面这句可以删掉:
Bitmap barcode = bundle == null ? null :
(Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);
然后把DecodeHandler.java的decode()方法也改一下:
删掉下面的部分
Bundle bundle = new Bundle();
bundle.putParcelable(DecodeThread.BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap());
message.setData(bundle);
zxing全屏识别(v2.5.0崩溃问题记录)的更多相关文章
- 在VC++6.0开发中实现全屏显示
全屏显示是一些应用软件程序必不可少的功能.比如在用VC++编辑工程源文件或编辑对话框等资源时,选择菜单“View\Full Screen”,即可进入全屏显示状态,按“Esc”键后会退出全屏显示状态. ...
- UI: 窗口全屏, 窗口尺寸
窗口全屏 窗口尺寸 示例1.窗口全屏UI/FullScreen.xaml <Page x:Class="Windows10.UI.FullScreen" xmlns=&quo ...
- 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸
[源码下载] 背水一战 Windows 10 (3) - UI: 窗口全屏, 窗口尺寸 作者:webabcd 介绍背水一战 Windows 10 之 UI 窗口全屏 窗口尺寸 示例1.窗口全屏UI/F ...
- MFC 带Ribbonbar的窗口 实现全屏和取消全屏
void CMainFrame::FullScreen(){ m_wndRibbonBar.ShowWindow(SW_HIDE);//隐藏工具栏 m_wndStatusBar. ...
- js控制全屏及退出全屏
js控制全屏及退出全屏,网上很多代码例子,我这里需求和标准的有点出入: 1.当用户点击某按钮,触发iframe下的页面全屏. 2.不允许用户退出全屏. 解决第一点,触发全屏可以按照网上的例子,代码如下 ...
- Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android 4.0平板底部状态栏的方法)
http://www.xuebuyuan.com/558284.html 方法一 public class MainActivity extends Activity { @Override prot ...
- Phonegap 3.0 设置APP是否全屏
Phonegap 3.0 默认是全屏,如需要取消全屏,可手动修改config, 在APP/res/xml/config.xml文件可设置preference: <?xml version='1. ...
- Android6.0 源码修改之 仿IOS添加全屏可拖拽浮窗返回按钮
前言 之前写过屏蔽系统导航栏功能的文章,具体可看Android6.0 源码修改之屏蔽导航栏虚拟按键(Home和RecentAPP)/动态显示和隐藏NavigationBar 在某些特殊定制的版本中要求 ...
- Android学习之Android 5.0分享动画实现微信点击全屏效果
Android5.0过渡动画,请看 http://blog.csdn.net/qq_16131393/article/details/51112772 今天用分享动画实现微信点击全屏效果 本文源代码下 ...
随机推荐
- css写复选框
前面讲过<完全使用css编写复选框>,后来在深入学习sass过程中,发现:这种写法虽然也能达到目的,但是稍嫌复杂了一点.这里介绍一种可以说更简单一点的方法,其实也就是html结构更简单一点 ...
- jq 上传下载进度条
里面只演示了下载的,挂载的是我的七牛服务器上的内容,上传事件和下载是一模一样的,为了大家不乱上传东西到我的服务器,而且我的服务器容量也不大,这里只展示了下载.代码: <!DOCTYPE html ...
- 29.Mongodb可视化工具 Studio 3t
Studio 3T 链接地址:https://pan.baidu.com/s/1X-Sqk50Xm76NJIZOz0ehFw 密码:td2a 安装配置成功链接本地如图所示:
- 代码:css3动画效果demo
四行文字会逐次掉落: 如果要停留在最后一帧的动画,注意要用forwards,不要用both. <style type="text/css"> @-webkit-key ...
- foreachPartition来写数据库
foreachPartition,在生产环境中,通常来说,都使用foreachPartition来写数据库的 使用批处理操作(一条SQL和多组参数) 发送一条SQL语句,发送一次 一下子就批量插入10 ...
- canal 入门(基于docker)
第一步:安装MySQL:(可以参考:https://my.oschina.net/amhuman/blog/1941540) 命令: sudo docker run -it -d --restart ...
- JAVA Spring Cloud 注册中心 Eureka 相关配置
转载至 https://www.cnblogs.com/fangfuhai/p/7070325.html Eureka客户端配置 1.RegistryFetchIntervalSecon ...
- jsp中文乱码
<%@page pageEncoding="UTF-8"%> <meta http-equiv="Content-Type" content= ...
- 异常+远程控制Linux-14
什么是异常 a=8950/0 ZeroDivisioonError: division by zero print (a) ************** b = [1,2] ...
- python3.6.2(32位)的安装-1
简介:Python不需要编译成机器代码,是解释执行.解释器是机器指令,CPU执行解释器,解释器执行代码. 1.Python官网下载地址:https://www.python.org/,选择Downlo ...