@@ -316,34 +316,41 @@ private void drawLaserLine(Canvas canvas, Rect frame) {
316
316
* @param point
317
317
*/
318
318
private void drawLaserLineFullScreen (Canvas canvas , Point point ) {
319
- if (scannerOptions .getLaserStyle () == ScannerOptions .LaserStyle .COLOR_LINE ) {
319
+ ScannerOptions .LaserStyle laserLineStyle = scannerOptions .getLaserStyle ();
320
+ if (laserLineStyle == ScannerOptions .LaserStyle .COLOR_LINE ) {
320
321
paint .setStyle (Paint .Style .FILL );
321
322
paint .setColor (scannerOptions .getLaserLineColor ());// 设置扫描线颜色
322
323
canvas .drawRect (0 , laserLineTop , point .x , laserLineTop + laserLineHeight , paint );
323
- } else {
324
- if (laserLineBitmap == null )//图片资源文件转为 Bitmap
324
+ return ;
325
+ }
326
+ // 图片资源文件转为 Bitmap
327
+ if (laserLineBitmap == null ) {
328
+ if (laserLineStyle == ScannerOptions .LaserStyle .DRAWABLE_LINE ||
329
+ laserLineStyle == ScannerOptions .LaserStyle .DRAWABLE_GRID ) {
330
+ laserLineBitmap = Scanner .drawableToBitmap (scannerOptions .getLaserLineDrawable ());
331
+ } else {
325
332
laserLineBitmap = BitmapFactory .decodeResource (getResources (), scannerOptions .getLaserLineResId ());
326
- int height = laserLineBitmap .getHeight ();//取原图高
327
- //网格图片
328
- if (scannerOptions .getLaserStyle () == ScannerOptions .LaserStyle .RES_GRID ) {
329
- int dstRectFTop = 0 ;
330
- if (laserLineTop >= height ) {
331
- dstRectFTop = laserLineTop - height ;
332
- }
333
- RectF dstRectF = new RectF (0 , dstRectFTop , point .x , laserLineTop );
334
- Rect srcRect = new Rect (0 , (int ) (height - dstRectF .height ()), laserLineBitmap .getWidth (), height );
335
- canvas .drawBitmap (laserLineBitmap , srcRect , dstRectF , paint );
336
333
}
337
- //线条图片
338
- else {
339
- //如果没有设置线条高度,则用图片原始高度
340
- if (laserLineHeight == dp2px ( ScannerOptions .DEFAULT_LASER_LINE_HEIGHT )) {
341
- laserLineHeight = laserLineBitmap . getHeight () / 2 ;
342
- }
343
- Rect laserRect = new Rect ( 0 , laserLineTop , point . x , laserLineTop + laserLineHeight );
344
- canvas . drawBitmap ( laserLineBitmap , null , laserRect , paint ) ;
334
+ }
335
+ int height = laserLineBitmap . getHeight (); //取原图高
336
+ // 网格图片
337
+ if (laserLineStyle == ScannerOptions .LaserStyle . RES_GRID ||
338
+ laserLineStyle == ScannerOptions . LaserStyle . DRAWABLE_GRID ) {
339
+ int dstRectFTop = 0 ;
340
+ if ( laserLineTop >= height ) {
341
+ dstRectFTop = laserLineTop - height ;
345
342
}
343
+ RectF dstRectF = new RectF (0 , dstRectFTop , point .x , laserLineTop );
344
+ Rect srcRect = new Rect (0 , (int ) (height - dstRectF .height ()), laserLineBitmap .getWidth (), height );
345
+ canvas .drawBitmap (laserLineBitmap , srcRect , dstRectF , paint );
346
+ return ;
346
347
}
348
+ // 线条图片, 如果没有设置线条高度,则用图片原始高度
349
+ if (laserLineHeight == dp2px (ScannerOptions .DEFAULT_LASER_LINE_HEIGHT )) {
350
+ laserLineHeight = laserLineBitmap .getHeight () / 2 ;
351
+ }
352
+ Rect laserRect = new Rect (0 , laserLineTop , point .x , laserLineTop + laserLineHeight );
353
+ canvas .drawBitmap (laserLineBitmap , null , laserRect , paint );
347
354
}
348
355
349
356
void drawViewfinder () {
0 commit comments