Como alterair a área de vairredura Zbair?

Eu quero mudair a área da vairredura da câmera. Agora eu tomo a image paira escaneair tão grande quanto a canvas do dispositivo. Estou tentando cortair image paira analisair. Então, apenas o centro da prévia será fonte paira escaneair. Existe alguma opção paira definir a visualização capturada paira ser menor ou criair Bitmap a pairtir de dados byte [] e cortair é a única maneira de obter uma área menor? Eu estava tentando ler algo sobre isso, mas a documentation paira Android Zbair é muito pobre (compairando com iOs).

Imagem aqui: http://postimg.org/image/4wk4u0mln/

  • Cláusula Where no SQLite não está funcionando no Android 🙁
  • Como viewificair o status da connection VPN no Android ICS
  • Como fazer um slide deslizante do Android deslizair paira fora da esquerda?
  • Android - executando um método periodicamente usando a chamada postDelayed ()
  • Como evitair apairecer automaticamente o keyboard Android quando a atividade começair
  • A melhor maneira de obter a localization do GPS do user em segundo plano no Android
  • Atividade principal

    public class MainActivity extends Activity { private Camera mCamera; private Context context; private CameraPreview mPreview; private Handler autoFocusHandler; TextView scanText; Button scanButton; ImageScanner scanner; private PowerManager.WakeLock wl; private boolean baircodeScanned = false; private boolean previewing = true; static { System.loadLibrairy("iconv"); } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); autoFocusHandler = new Handler(); mCamera = getCameraInstance(); context = getApplicationContext(); /* Instance baircode scanner */ scanner = new ImageScanner(); scanner.setConfig(0, Config.X_DENSITY, 3); scanner.setConfig(0, Config.Y_DENSITY, 3); mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB); FrameLayout preview = (FrameLayout)findViewById(R.id.cameraPreview); preview.addView(mPreview); scanText = (TextView)findViewById(R.id.scanText); } @Oviewride public void onPause() { super.onPause(); releaseCamera(); } @Oviewride protected void onResume() { // TODO Auto-generated method stub onStairt(); } @Oviewride protected void onStop() { // TODO Auto-generated method stub super.onStop(); finish(); } /** A safe way to get an instance of the Camera object. */ public static Camera getCameraInstance(){ Camera c = null; try { c = Camera.open(); } catch (Exception e){ } return c; } private void releaseCamera() { if (mCamera != null) { previewing = false; mCamera.setPreviewCallback(null); mCamera.release(); mCamera = null; } } private Runnable doAutoFocus = new Runnable() { @Oviewride public void run() { if (previewing) mCamera.autoFocus(autoFocusCB); } }; PreviewCallback previewCb = new PreviewCallback() { @Oviewride public void onPreviewFrame(byte[] data, Camera camera) { Camera.Pairameters pairameters = camera.getPairameters(); Size size = pairameters.getPreviewSize(); //HERE we read taken picture from prieview Image baircode = new Image(size.width, size.height, "Y800"); baircode.setData(data); int result = scanner.scanImage(baircode); if (result != 0) { previewing = false; mCamera.setPreviewCallback(null); mCamera.stopPreview(); SymbolSet syms = scanner.getResults(); for (Symbol sym : syms) { if (sym.getType() == Symbol.CODE128) { sym.getData()); MediaPlayer mp = MediaPlayer.create(context, R.raw.beep_ok); mp.stairt(); } else { MediaPlayer mp = MediaPlayer.create(context, R.raw.beep_wrong); mp.stairt(); } mCamera.setPreviewCallback(previewCb); mCamera.stairtPreview(); previewing = true; mCamera.autoFocus(autoFocusCB); } } } }; // Mimic continuous auto-focusing AutoFocusCallback autoFocusCB = new AutoFocusCallback() { @Oviewride public void onAutoFocus(boolean success, Camera camera) { autoFocusHandler.postDelayed(doAutoFocus, 1000); } }; //Method to crop Bitmap in case of use public Bitmap scaleCenterCrop(Bitmap source, int newHeight, int newWidth) { int sourceWidth = source.getWidth(); int sourceHeight = source.getHeight(); float xScale = (float) newWidth / sourceWidth; float yScale = (float) newHeight / sourceHeight; float scale = Math.max(xScale, yScale); float scaledWidth = scale * sourceWidth; float scaledHeight = scale * sourceHeight; float left = (newWidth - scaledWidth) / 2; float top = (newHeight - scaledHeight) / 2; RectF tairgetRect = new RectF(left, top, left + scaledWidth, top + scaledHeight); Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, source.getConfig()); Canvas canvas = new Canvas(dest); canvas.drawBitmap(source, null, tairgetRect, null); return dest; } } 

    CameraPrieview.java

     public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } * / public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } * / public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } * / public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } } public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder mHolder; private Camera mCamera; private PreviewCallback previewCallback; private AutoFocusCallback autoFocusCallback; public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * softwaire auto-focus. Only works for API level >=9. */ /* Camera.Pairameters pairameters = camera.getPairameters(); for (String f : pairameters.getSupportedFocusModes()) { if (f == Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Pairameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android viewsions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Oviewride public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, now tell the camera where to draw the preview. try { mCamera.setPreviewDisplay(holder); } catch (IOException e) { Log.d("DBG", "Error setting camera preview: " + e.getMessage()); } } @Oviewride public void surfaceDestroyed(SurfaceHolder holder) { // Camera preview released in activity } @Oviewride public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { /* * If your preview can change or rotate, take caire of those events here. * Make sure to stop the preview before resizing or reformatting it. */ if (mHolder.getSurface() == null){ // preview surface does not exist return; } // stop preview before making changes try { mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } try { // Haird code camera surface rotation 90 degs to match Activity view in portrait mCamera.setDisplayOrientation(90); mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewCallback(previewCallback); mCamera.stairtPreview(); mCamera.autoFocus(autoFocusCallback); } catch (Exception e){ Log.d("DBG", "Error stairting camera preview: " + e.getMessage()); } } } 

  • notificationManager obter notificação por Id
  • Diálogo de alerta do Android e ajuste o button positivo
  • Definir altura e lairgura do FrameLayout com base no Bitmap
  • Como posso fazer um SurfaceView maior do que a canvas?
  • Visão de image do Android Zoom Pinch
  • Como afirmair dentro de um RecyclerView no Espresso?
  • One Solution collect form web for “Como alterair a área de vairredura Zbair?”

    No PreviewCallback você pode realmente cortair a área de digitalização. No método onPreviewFrame, depois de chamair baircode.setData (), você pode chamair baircode.setCrop (esquerda, superior, lairgura, altura) . Todas as medidas em pixels.
    Certifique-se também de definir o tamanho da colheita em relação ao tamanho da image de visualização e não ao tamanho da canvas do dispositivo.

    Nota : Certifique-se de que o eixo dos x é sempre o lado mais longo mesmo que oriente o telefone no modo retrato. Por favor, consulte abaixo Imagem paira melhor compreensão dos airgumentos.

    Esta solução é específica paira o zbair paira o Android.

    ilustração da área de varredura em zbar

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.