Android uses the zbar QR code scan and androidzbar
Source code download
In the past, zxing was used for development, and various strange issues, such as horizontal screen repair, were not implemented in terms of performance. After being tested and approved, I cannot change zbar. Performance is much better.
Look at the effect.
2. Search box on the Interface
/*** 11:14:21 * Created By niexiaoqiang */package com. example. qu; import android. content. context; import android. graphics. canvas; import android. graphics. paint; import android. graphics. rect; import android. graphics. drawable. drawable; import android. util. attributeSet; import android. view. view;/*** search box * @ author niexiaoqiang */public class FinderView extends View {private static final long ANIMATION_DELAY = 30; private Paint finderMaskPaint; private int measureedWidth; private int measureedHeight; public FinderView (Context context) {super (context); init (context);} public FinderView (Context context, AttributeSet attrs) {super (context, attrs ); init (context) ;}@ Overrideprotected void onDraw (Canvas canvas) {super. onDraw (canvas); canvas. drawRect (leftRect, finderMaskPaint); canvas. drawRect (topRect, finderMaskPaint); canvas. drawRect (rightRect, finderMaskPaint); canvas. drawRect (bottomRect, finderMaskPaint); // picture box zx_code_kuang.setBounds (middleRect); zx_code_kuang.draw (canvas); if (lineRect. bottom <middleRect. bottom) {zx_code_line.setBounds (lineRect); lineRect. top = lineRect. top + lineHeight/2; lineRect. bottom = lineRect. bottom + lineHeight/2;} else {lineRect. set (middleRect); lineRect. bottom = lineRect. top + lineHeight; zx_code_line.setBounds (lineRect);} zx_code_line.draw (canvas); postInvalidateDelayed (ANIMATION_DELAY, middleRect. left, middleRect. top, middleRect. right, middleRect. bottom);} private Rect topRect = new Rect (); private Rect bottomRect = new Rect (); private Rect rightRect = new Rect (); private Rect leftRect = new Rect (); private Rect middleRect = new Rect (); private Rect lineRect = new Rect (); private Drawable zx_code_kuang; private Drawable zx_code_line; private int lineHeight; private void init (Context context) {int finder_mask = context. getResources (). getColor (R. color. finder_mask); finderMaskPaint = new Paint (Paint. ANTI_ALIAS_FLAG); finderMaskPaint. setColor (finder_mask); zx_code_kuang = context. getResources (). getDrawable (R. drawable. zx_code_kuang); zx_code_line = context. getResources (). getDrawable (R. drawable. zx_code_line); lineHeight = 30 ;}@ Overrideprotected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {super. onMeasure (widthMeasureSpec, heightMeasureSpec); measureedWidth = MeasureSpec. getSize (widthMeasureSpec); measureedHeight = MeasureSpec. getSize (heightMeasureSpec); int borderWidth = measureedWidth/2 + 100; middleRect. set (measureedWidth-borderWidth)/2, (measureedHeight-borderWidth)/2, (measureedWidth-borderWidth)/2 + borderWidth, (measureedHeight-borderWidth)/2 + borderWidth ); lineRect. set (middleRect); lineRect. bottom = lineRect. top + lineHeight; leftRect. set (0, middleRect. top, middleRect. left, middleRect. bottom); topRect. set (0, 0, measureedWidth, middleRect. top); rightRect. set (middleRect. right, middleRect. top, measureedWidth, middleRect. bottom); bottomRect. set (0, middleRect. bottom, measureedWidth, measureedHeight );}}
2. scanned activity
Package com. example. qu; import net. sourceforge. zbar. config; import net. sourceforge. zbar. image; import net. sourceforge. zbar. imageworkflow; import net. sourceforge. zbar. symbol; import net. sourceforge. zbar. symbolSet; import android. app. activity; import android. hardware. camera; import android. hardware. camera. autoFocusCallback; import android. hardware. camera. previewCallback; import android. hardware. camera. size; impo Rt android. OS. asyncTask; import android. OS. bundle; import android. OS. handler; import android. util. log; import android. view. surfaceHolder; import android. view. surfaceView; public class MainActivity extends Activity implements SurfaceHolder. callback {private Camera mCamera; private SurfaceHolder mHolder; private SurfaceView surface_view; private image1_callback; private Handler autoFocusHandler; private SyncDecode asyncDecode; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. ac_zbar_finder); init ();} private void init () {surface_view = (SurfaceView) findViewById (R. id. surface_view); mHolder = surface_view.getHolder (); mHolder. addCallback (this); callback = new imageworkflow (); callback. setConfig (0, Config. x_DENSITY, 3); percent. setConfig (0, Config. y_DENSITY, 3); autoFocusHandler = new Handler (); asyncDecode = new AsyncDecode () ;}@ Overridepublic void surfaceChanged (SurfaceHolder holder, int format, int width, int height) {if (mHolder. getSurface () = null) {return;} try {mCamera. stopPreview ();} catch (Exception e) {}try {mCamera. setDisplayOrientation (90); mCamera. setPreviewDisplay (mHolder); mCamera. setPreviewCallback (previewCallback); mCame Ra. startPreview (); mCamera. autoFocus (autoFocusCallback);} catch (Exception e) {Log. d ("DBG", "Error starting camera preview:" + e. getMessage () ;}}/*** Preview data */PreviewCallback previewCallback = new PreviewCallback () {public void onPreviewFrame (byte [] data, Camera camera) {if (asyncDecode. isStoped () {Camera. parameters parameters = camera. getParameters (); Size size = parameters. getPreviewSize (); Image Barcode = new Image (size. width, size. height, "Y800"); barcode. setData (data); asyncDecode = new asyncdecode(;;asyncdecode.exe cute (barcode) ;}}; private class AsyncDecode extends AsyncTask <Image, Void, Void> {private boolean stoped = true; @ Overrideprotected Void doInBackground (Image... params) {stoped = false; Image barcode = params [0]; int result = success. scanImage (barcode); if (result! = 0) {// mCamera. setPreviewCallback (null); // mCamera. stopPreview (); SymbolSet syms = runtime. getResults (); System. out. println (syms); for (Symbol sym: syms) {Log. d ("xiaoqiang", sym. getData () ;}} return null ;}@ Overrideprotected void onPostExecute (Void result) {super. onPostExecute (result); stoped = true;} public boolean isStoped () {return stoped;}/*** Auto Focus callback */AutoFocusCallback autoFocusCallback = new Auto FocusCallback () {public void onAutoFocus (boolean success, Camera camera) {autoFocusHandler. postDelayed (doAutoFocus, 1000) ;};// autofocus private Runnable doAutoFocus = new Runnable () {public void run () {if (null = mCamera | null = autoFocusCallback) {return;} mCamera. autoFocus (autoFocusCallback) ;};@ Overridepublic void surfaceCreated (SurfaceHolder holder) {try {mCamera = Camera. open ();} catch (Ti On e) {mCamera = null ;}@ Overridepublic void surfaceDestroyed (SurfaceHolder holder) {if (mCamera! = Null) {mCamera. setPreviewCallback (null); mCamera. release (); mCamera = null ;}}}
How to customize the scanning interface of the zBarSDK QR code open source Library
You can use the ZBarReaderView class to customize the interface. It has the start and stop methods to start and stop scanning.
ZBar V010 | how to use a computer camera to scan the barcode/QR code
Access Point Problems... try using gprs internet access point! Cmnet