主要修改onDraw方法里面的属性……

/*** This view is overlaid on top of the camera preview. It adds the viewfinder rectangle and partial* transparency outside it, as well as the laser scanner animation and result points.*/
public final class ViewfinderView extends View {private static final int[] SCANNER_ALPHA = {0, 64, 128, 192, 255, 192, 128, 64};private static final long ANIMATION_DELAY = 100L;private static final int OPAQUE = 0xFF;private final Paint paint;private Bitmap resultBitmap;private final int maskColor;private final int resultColor;private final int frameColor;private final int laserColor;private final int resultPointColor;private int scannerAlpha;private Collection<ResultPoint> possibleResultPoints;private Collection<ResultPoint> lastPossibleResultPoints;// This constructor is used when the class is built from an XML resource.public ViewfinderView(Context context, AttributeSet attrs) {super(context, attrs);// Initialize these once for performance rather than calling them every time in onDraw().paint = new Paint();Resources resources = getResources();maskColor = resources.getColor(R.color.viewfinder_mask);resultColor = resources.getColor(R.color.result_view);frameColor = resources.getColor(R.color.viewfinder_frame);laserColor = resources.getColor(R.color.viewfinder_laser);resultPointColor = resources.getColor(R.color.possible_result_points);scannerAlpha = 0;possibleResultPoints = new HashSet<ResultPoint>(5);}/*** 中间那条线每次刷新移动的距离*/private static final int SPEEN_DISTANCE = 20;/*** 中间滑动线的最顶端位置*/private int slideTop;/*** 中间滑动线的最底端位置*/private int slideBottom;/*** 扫描框中的中间线的宽度*/private static final int MIDDLE_LINE_WIDTH = 6;/*** 扫描框中的中间线的与扫描框左右的间隙*/private static final int MIDDLE_LINE_PADDING = 10;boolean isFirst;@Overridepublic void onDraw(Canvas canvas) {Rect frame = CameraManager.get().getFramingRect();if (frame == null) {return;}//初始化中间线滑动的最上边和最下边if (!isFirst) {isFirst = true;slideTop = frame.top;slideBottom = frame.bottom;}//获取屏幕的宽和高int width = canvas.getWidth();int height = canvas.getHeight();// Draw the exterior (i.e. outside the framing rect) darkened//画出扫描框外面的阴影部分paint.setColor(resultBitmap != null ? resultColor : maskColor);canvas.drawRect(0, 0, width, frame.top, paint);canvas.drawRect(0, frame.top, frame.left, frame.bottom + 1, paint);canvas.drawRect(frame.right + 1, frame.top, width, frame.bottom + 1, paint);canvas.drawRect(0, frame.bottom + 1, width, height, paint);if (resultBitmap != null) {// Draw the opaque result bitmap over the scanning rectanglepaint.setAlpha(OPAQUE);canvas.drawBitmap(resultBitmap, frame.left, frame.top, paint);} else {//绘制中间的线,每次刷新界面,中间的线往下移动SPEEN_DISTANCEpaint.setColor(laserColor);slideTop += SPEEN_DISTANCE;if (slideTop >= frame.bottom) {slideTop = frame.top;}canvas.drawRect(frame.left + 2, slideTop - 1, frame.right - 1, slideTop + 2, paint);// 画出四个角// Draw four cornerspaint.setColor(getResources().getColor(R.color.colorBillStatus1));// 左上角(top left corner)canvas.drawRect(frame.left, frame.top, frame.left + 35, frame.top + 8, paint);canvas.drawRect(frame.left, frame.top, frame.left + 8, frame.top + 35, paint);// 右上角(top right corner)canvas.drawRect(frame.right - 35, frame.top, frame.right, frame.top + 8, paint);canvas.drawRect(frame.right - 8, frame.top, frame.right, frame.top + 35, paint);// 左下角(Bottom left corner)canvas.drawRect(frame.left, frame.bottom - 8, frame.left + 35, frame.bottom, paint);canvas.drawRect(frame.left, frame.bottom - 35, frame.left + 8, frame.bottom, paint);// 右下角(Bottom right corner)canvas.drawRect(frame.right - 35, frame.bottom - 8, frame.right, frame.bottom, paint);canvas.drawRect(frame.right - 8, frame.bottom - 35, frame.right, frame.bottom, paint);Collection<ResultPoint> currentPossible = possibleResultPoints;Collection<ResultPoint> currentLast = lastPossibleResultPoints;if (currentPossible.isEmpty()) {lastPossibleResultPoints = null;} else {possibleResultPoints = new HashSet<ResultPoint>(5);lastPossibleResultPoints = currentPossible;paint.setAlpha(OPAQUE);paint.setColor(resultPointColor);for (ResultPoint point : currentPossible) {canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 6.0f, paint);}}if (currentLast != null) {paint.setAlpha(OPAQUE / 2);paint.setColor(resultPointColor);for (ResultPoint point : currentLast) {canvas.drawCircle(frame.left + point.getX(), frame.top + point.getY(), 3.0f, paint);}}// Request another update at the animation interval, but only repaint the laser line,// not the entire viewfinder mask.//只刷新扫描框的内容,其他地方不刷新postInvalidateDelayed(ANIMATION_DELAY, frame.left, frame.top, frame.right, frame.bottom);}}public void drawViewfinder() {resultBitmap = null;invalidate();}/*** Draw a bitmap with the result points highlighted instead of the live scanning display.** @param barcode An image of the decoded barcode.*/public void drawResultBitmap(Bitmap barcode) {resultBitmap = barcode;invalidate();}public void addPossibleResultPoint(ResultPoint point) {possibleResultPoints.add(point);}}

Android 修改zxing二维码样式相关推荐

  1. Android 基于Zxing二维码扫描的光速实现

    Android 十分钟光速实现二维码扫描 前言 在项目中要使用到二维码的相关内容,我们第一时间想到的是使用大名鼎鼎的zxing或者ZBar开源框架: github-zxing官方库的地址 github ...

  2. Android 集成zxing二维码扫描、自定义

    项目主要有zxing的基本使用,包含扫描回调.连续扫描.自定义扫描框: 一.依赖库 implementation 'com.journeyapps:zxing-android-embedded:4.3 ...

  3. 自定义/修改微信二维码样式

    在写项目的时候遇到的一个需求,登录和注册都可以通过扫描微信的二维码来实现,但是在做的时候发现微信有一些它自带的样式,并且无法通过CSS直接修改. 通过查微信的开发者文档发现是支持修改的 wxHandl ...

  4. 基于ZXing Android实现生成二维码图片和相机扫描二维码图片即时解码的功能

    NextQRCode ZXing开源库的精简版 **基于ZXing Android实现生成二维码图片和相机扫描二维码图片即时解码的功能 原文博客 附源码下载地址** 与原ZXingMini项目对比 N ...

  5. Android ZXing 二维码、条形码扫描介绍

    最近公司的Android项目需要用到摄像头做条码或二维码的扫描,Google一下,发现一个开源的 ZXing项目.它提供二维码和条形码的扫描.扫描条形码就是直接读取条形码的内容,扫描二维码是按照自己指 ...

  6. Zxing生成自定义二维码样式

    Zxing生成自定义二维码样式 现在几乎每个app都带有二维码,但是google提供的zxing包,只给我们提供了核心的二维码算法,而开发过程中经常有自定义二维码的样式的需求,这时候我们就要自己写工具 ...

  7. Android zxing 二维码扫描和生成方法(简单版)

    前言 二维码大家都见识过,这里就不废话了,直接来干货. 步骤 导入依赖 compile 'com.google.zxing:core:3.2.1' //zxing核心依赖compile 'com.jo ...

  8. [Android开源]一个非常简单易用用来花式展示二维码样式生成的库QRCodeStyle

    类库说明 一个非常简单易用用来花式展示二维码样式生成的库 自由组合二维码样式 使用范例 设置带圆边圈的logo Bitmap logo = BitmapFactory.decodeResource(g ...

  9. 微信扫码登录(new WxLogin)-二维码样式修改

    一.自定义二维码样式 例如: .impowerBox .qrcode {width: 180px;} .impowerBox .title {display: none;} .impowerBox . ...

最新文章

  1. 使用关键点进行小目标检测
  2. 《剑指offer》——04. 二维数组中的查找——暴力法、线性查找——java实现
  3. 【Linux】一步一步学Linux——exec命令(208)
  4. Java并发:隐藏线程死锁
  5. 10-排序6 Sort with Swap(0, i) (25 分)
  6. Nacos: Namespace 和 Endpoint 在生产环境下的最佳实践
  7. Spring学习笔记002 - AOP
  8. 接口与抽象类的区别和联系
  9. Proxy Hosted Virtual
  10. python编码思维导图_Python入门之ATM+购物车代码版思维导图
  11. [云计算]交换机二层端口access、trunk、hybird的理解
  12. 桌面支持--teamviwer如果没装杀毒软件,会有警告
  13. 视频压缩软件如何下载
  14. 编译原理考试知识点总结
  15. plc程序加密解密方法解读
  16. 计算机关机键桌面,电脑关机快捷键是什么?
  17. 70万行代码、历时20年,一名开发人员写出的史诗般的计算机程序
  18. 计算机组成CPU最佳配置,计算机组成原理--CPU
  19. 求分享如何给短视频加特效
  20. linux看视频插件,Linux系统下安装Adobe Flash Player插件观播放视频

热门文章

  1. bidi(双向文字)与RTL布局总结
  2. 【操作系统】DOS界面与常用操作命令
  3. 图形编辑器:对齐功能的实现
  4. C++2022NOC之初赛数字规律
  5. 资源整理 IC/FPGA
  6. 3D模型欣赏:Cyber-boy机车不良风男孩
  7. PHP+Mysql——博客系统(前端+后端-整套源码)
  8. wang zhe rong yao
  9. css伪类加垂直分割线
  10. 一. Mybits简单使用