Android QR code scan box plus Four corners and middle horizontal line automatically slide

Source: Internet
Author: User
Tags getcolor gety

Red to add Four Corners yellow for the scan line automatically slipped

/** Copyright (C) ZXing authors * * Licensed under the Apache License, Version 2.0 (the "License"); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * *http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable law or agreed to writing, software * Distributed under the License are distributed on An ' as is ' BASIS, * without warranties or CONDITIONS of any KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.*/Package Com.zxing.view;import Java.util.collection;import Java.util.hashset;import android.content.context;import Android.content.res.resources;import Android.graphics.bitmap;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.graphics.rect;import Android.util.attributeset;import Android.view.view;import Com.bawei.zxingdemo.r;import Com.google.zxing.resultpoint;import Com.zxing.camera.CameraManager;/** * This view are 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 Resul T points. 锟 all false copy 锟 Jin 锟 絍 iew 锟 catty copy 锟 Jin 锟 catty copy Shi called alkali copy 锟 pound copy show 锟 Jin copy*/Public finalClassViewfinderview extends View {PrivateStatic finalInt[] Scanner_alpha = {0,64,128,192,255,192,128,64};PrivateStatic finalLong Animation_delay =100L;PrivateStatic finalint OPAQUE =0xFF;PrivateFinal paint paint;PrivateBitmap Resultbitmap;Private finalIntMaskColor;Private finalIntResultcolor;Private finalIntFrameColor;Private finalIntLasercolor;Private finalIntResultpointcolor;PrivateIntScanneralpha;/** * Four green corner corresponding to the length*/private intScreenrate;/** * Four green corner corresponding to the width*/private static final int corner_width = 10;/** * Cell phone's screen density*/private static floatDensityPrivate collection<resultpoint>possibleresultpoints;Private collection<resultpoint>lastpossibleresultpoints;int count=0;//This constructor was used when the class was built from an XML resource.PublicViewfinderview (context context, AttributeSet Attrs) {Super (context, attrs);//Initialize these once for performance rather than calling them every//Time in OnDraw (). Paint =NewPaint (); 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);Density= Context.getresources (). Getdisplaymetrics (). density; Convert pixel to DP screenrate = (int) (20 *Density); } @OverridePublicvoidOnDraw (canvas canvas) {//Juan Time Fermium ECF 壂 æ 忔 锛 Imperial quantity untreated blemish like Blake bookmark regulation 壂 æ 忔 fermium 勫 ぇ Hao 忥 紝  level hygiene Ameramanager stated expiry refer 岄 bulb ki adjust Rect frame = Cameramanager.Get(). Getframingrect ();if (frame = =Null) {Return; }//Luen PK 彇 BA Chairman Wilson 箷 fermium 勫 Tel 岄int width =Canvas.getwidth ();int height =Canvas.getheight ();//Draw the exterior (i.e outside the framing rect) darkened//úã downloading gallium 弿 Jean Ricoh 闈 ㈢ Crypto Radiation Village award 閮-Hi 垎 锛 toric eizan å›žå¤ 涗 Kettle 閮-Hi 垎 锛 屾 壂 æ 忔 fermium Âμà Kono 闈 ㈠ Lang BA Chairman Wilson 箷 Juan 婇 Bulb 锛 屾 壂 æ 忔 fermium Âμà Lower 闈 ㈠ Lang BA Chairman Wilson 箷 Juan 嬮 Bulb//Gallium 弿 Jean Bang Crypto Chen "unexpectedly 闈 ㈠ Lang BA Chairman Wilson 箷 Chen" unexpectedly 锛 屾 壂 æ 忔 fermium 勫 Conferences Fork Roses Lang BA Chairman Wilson 箷 Å è¡#̈亞 pet 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{//úã plot 壂 æ 忔 fork Stroll kono fermium cancel 锛 屾? Eizan 8 Juan 儴 arrival?//Draw a pixel solid black border inside the framing rectPaint.setcolor (FrameColor); Canvas.drawrect (Frame.left, frame.top, Frame.right +1, Frame.top +2, paint); Canvas.drawrect (Frame.left, Frame.top +2, Frame.left +2, Frame.bottom-1, paint); Canvas.drawrect (Frame.right-1, Frame.top, Frame.right +1, Frame.bottom-1, paint); Canvas.drawrect (Frame.left, Frame.bottom-1, Frame.right +1, Frame.bottom +1, paint);//Draw a red "laser scanner" line through the middle to show//Decoding is active//úã painted 壂 æ 忔 Juan 嬮 bulb fermium 勫 瓧Paint.setcolor (Lasercolor); Paint.setalpha (Scanner_alpha[scanneralpha]); Scanneralpha = (Scanneralpha +1)%Scanner_alpha.length;int middle = count%frame.height () + frame.top; Canvas.drawrect (Frame.left + 2, middle-1, frame.right-1, Middle + 2, paint); count+=3;//Draw a corner on the edge of the scan box, a total of 8 sectionsPaint.setcolor (Color.green); Canvas.drawrect (Frame.left, frame.top, Frame.left + screenrate, Frame.top + corner_width, paint); Canvas.drawrect (Frame.left, frame.top, Frame.left + corner_width, Frame.top + screenrate, paint); Canvas.drawrect (Frame.right-screenrate, Frame.top, frame.right, Frame.top + corner_width, paint); Canvas.drawrect (Frame.right-corner_width, Frame.top, frame.right, Frame.top + screenrate, paint); Canvas.drawrect (Frame.left, frame.bottom-corner_width, Frame.left + screenrate, frame.bottom, paint); Canvas.drawrect (Frame.left, frame.bottom-screenrate, Frame.left + corner_width, frame.bottom, paint); Canvas.drawrect (Frame.right-screenrate, Frame.bottom-corner_width, Frame.right, Frame.bottom, paint); Canvas.drawrect (Frame.right-corner_width, Frame.bottom-Screenrate, 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, p aint); }} if (currentlast! = null) {Paint.setalpha (OPAQUE/2); Paint.setcolor (Resultpointcolor); for (Resultpoint Point:curr Entlast) {canvas.drawcircle (Frame.left + point.getx (), Frame.top + point.gety (), 3.0f, Paint);}} Request another update at the animation interval, and only//repaint the laser line,//not the entire viewfinder mask . Å è¡#̈亞 id ã version 壂 æ 忔 fermium 勫 search锛 yue decyl 紝 å duo Yeast Rice 鍦 Edition 闀挎柟褰 Juan Indent ID Ã? Postinvalidatedelayed (Animation_delay, Frame.left, Frame.top, Frame.right, Frame.bottom); }} public void Drawviewfinder () {resultbitmap = null, invalidate ();}/** * Draw a bitmap with the result points Highlig Hted 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 QR code scan box plus Four corners and middle horizontal line automatically slide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.