ZXing Barcode Reader: How to make custom border around capture screen?

后端 未结 4 1339
时光取名叫无心
时光取名叫无心 2020-12-30 11:38

I want to put custom border around zxing capture screen (camera screen). What modification would I need to make for this? Which activity and layouts would I need to change

4条回答
  •  一整个雨季
    2020-12-30 12:20

    This question already has an answer. But if someone needs how to draw a border around capture screen, here is the code. inazaruk's answer is correct. My answer is just an extension for that.

     //initialize new paint in the constructor
     Paint borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
     borderPaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
    
     //inside onDraw
     int distance = (frame.bottom - frame.top) / 4;
     int thickness = 15;
    
     //top left corner
     canvas.drawRect(frame.left - thickness, frame.top - thickness, distance + frame.left, frame.top, borderPaint);
     canvas.drawRect(frame.left - thickness, frame.top, frame.left, distance + frame.top, borderPaint);
    
     //top right corner
     canvas.drawRect(frame.right - distance, frame.top - thickness, frame.right + thickness, frame.top, borderPaint);
     canvas.drawRect(frame.right, frame.top, frame.right + thickness, distance + frame.top, borderPaint);
    
     //bottom left corner
     canvas.drawRect(frame.left - thickness, frame.bottom, distance + frame.left, frame.bottom + thickness, borderPaint);
     canvas.drawRect(frame.left - thickness, frame.bottom - distance, frame.left, frame.bottom, borderPaint);
    
     //bottom right corner
     canvas.drawRect(frame.right - distance, frame.bottom, frame.right + thickness, frame.bottom + thickness, borderPaint);
     canvas.drawRect(frame.right, frame.bottom - distance, frame.right + thickness, frame.bottom, borderPaint);
    

提交回复
热议问题