How to improve the focus speed of camera?












4















I use dm77/barcodescanner library to Scan QrCode. But When using This in my app, camera focus time is 1000L, and this is not optimal parameter for all phones.



How to improve the focus speed of camera?










share|improve this question





























    4















    I use dm77/barcodescanner library to Scan QrCode. But When using This in my app, camera focus time is 1000L, and this is not optimal parameter for all phones.



    How to improve the focus speed of camera?










    share|improve this question



























      4












      4








      4


      0






      I use dm77/barcodescanner library to Scan QrCode. But When using This in my app, camera focus time is 1000L, and this is not optimal parameter for all phones.



      How to improve the focus speed of camera?










      share|improve this question
















      I use dm77/barcodescanner library to Scan QrCode. But When using This in my app, camera focus time is 1000L, and this is not optimal parameter for all phones.



      How to improve the focus speed of camera?







      android zxing barcode-scanner






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 12:12









      MaHDi

      777




      777










      asked Jan 2 at 8:14









      Abolfazl KalamatiAbolfazl Kalamati

      1518




      1518
























          1 Answer
          1






          active

          oldest

          votes


















          3














          I found the answer to this question with help @TeunVR in github.
          You must create a class and extends from ZXingScannerView and Override setupCameraPreview and setAutoFocus .



          public class ZXingAutofocusScannerView extends ZXingScannerView {

          private boolean callbackFocus = false ;

          public ZXingAutofocusScannerView(Context context) {
          super(context);
          }


          @Override
          public void setupCameraPreview(CameraWrapper cameraWrapper) {



              Camera.Parameters parameters= cameraWrapper.mCamera.getParameters();
          if(parameters != null)
          {
          try {
          parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
          cameraWrapper.mCamera.setParameters(parameters);
          }catch (Exception e)
          {
          fallbackFocus = true ;
          }
          // cameraWrapper.mCamera.getParameters()

          }


          super.setupCameraPreview(cameraWrapper);
          }
          @Override
          public void setAutoFocus(boolean state) {
          super.setAutoFocus(callbackFocus);
          }
          }


          Now you must use this class instead ZXingScannerView.



          public class SimpleScannerActivity extends AppCompatActivity implements 
          ZXingAutofocusScannerView.ResultHandler {

          private ZXingAutofocusScannerView mScannerView;

          @Override
          public void onCreate(Bundle state) {
          super.onCreate(state);
          mScannerView = new ZXingAutofocusScannerView(this);
          setContentView(mScannerView);

          @Override
          public void onResume() {
          super.onResume();
          mScannerView.setResultHandler(this);
          mScannerView.startCamera();
          }

          @Override
          public void onPause() {
          super.onPause();
          mScannerView.stopCamera();
          }

          @Override
          public void handleResult(Result rawResult) {
          Toast.makeText(this, ""+rawResult.getText(), Toast.LENGTH_SHORT).show();
          mScannerView.resumeCameraPreview(this);
          }
          }


          If You Use Koltin see this answer :



          class ZXingAutofocusScannerView(context: Context) : 
          ZXingScannerView(context) {
          private val TAG = ZXingAutofocusScannerView::class.qualifiedName

          private var callbackFocus = false

          override fun setupCameraPreview(cameraWrapper: CameraWrapper?) {
          cameraWrapper?.mCamera?.parameters?.let{parameters->
          try {
          parameters.focusMode =
          Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
          cameraWrapper.mCamera.parameters = parameters
          }catch(ex:Exception){
          Log.e(TAG, "Failed to set CONTINOUS_PICTURE", ex)
          callbackFocus = true
          }
          }
          super.setupCameraPreview(cameraWrapper)
          }

          override fun setAutoFocus(state: Boolean) {
          super.setAutoFocus(callbackFocus)
          }
          }





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003150%2fhow-to-improve-the-focus-speed-of-camera%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            I found the answer to this question with help @TeunVR in github.
            You must create a class and extends from ZXingScannerView and Override setupCameraPreview and setAutoFocus .



            public class ZXingAutofocusScannerView extends ZXingScannerView {

            private boolean callbackFocus = false ;

            public ZXingAutofocusScannerView(Context context) {
            super(context);
            }


            @Override
            public void setupCameraPreview(CameraWrapper cameraWrapper) {



                Camera.Parameters parameters= cameraWrapper.mCamera.getParameters();
            if(parameters != null)
            {
            try {
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
            cameraWrapper.mCamera.setParameters(parameters);
            }catch (Exception e)
            {
            fallbackFocus = true ;
            }
            // cameraWrapper.mCamera.getParameters()

            }


            super.setupCameraPreview(cameraWrapper);
            }
            @Override
            public void setAutoFocus(boolean state) {
            super.setAutoFocus(callbackFocus);
            }
            }


            Now you must use this class instead ZXingScannerView.



            public class SimpleScannerActivity extends AppCompatActivity implements 
            ZXingAutofocusScannerView.ResultHandler {

            private ZXingAutofocusScannerView mScannerView;

            @Override
            public void onCreate(Bundle state) {
            super.onCreate(state);
            mScannerView = new ZXingAutofocusScannerView(this);
            setContentView(mScannerView);

            @Override
            public void onResume() {
            super.onResume();
            mScannerView.setResultHandler(this);
            mScannerView.startCamera();
            }

            @Override
            public void onPause() {
            super.onPause();
            mScannerView.stopCamera();
            }

            @Override
            public void handleResult(Result rawResult) {
            Toast.makeText(this, ""+rawResult.getText(), Toast.LENGTH_SHORT).show();
            mScannerView.resumeCameraPreview(this);
            }
            }


            If You Use Koltin see this answer :



            class ZXingAutofocusScannerView(context: Context) : 
            ZXingScannerView(context) {
            private val TAG = ZXingAutofocusScannerView::class.qualifiedName

            private var callbackFocus = false

            override fun setupCameraPreview(cameraWrapper: CameraWrapper?) {
            cameraWrapper?.mCamera?.parameters?.let{parameters->
            try {
            parameters.focusMode =
            Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
            cameraWrapper.mCamera.parameters = parameters
            }catch(ex:Exception){
            Log.e(TAG, "Failed to set CONTINOUS_PICTURE", ex)
            callbackFocus = true
            }
            }
            super.setupCameraPreview(cameraWrapper)
            }

            override fun setAutoFocus(state: Boolean) {
            super.setAutoFocus(callbackFocus)
            }
            }





            share|improve this answer






























              3














              I found the answer to this question with help @TeunVR in github.
              You must create a class and extends from ZXingScannerView and Override setupCameraPreview and setAutoFocus .



              public class ZXingAutofocusScannerView extends ZXingScannerView {

              private boolean callbackFocus = false ;

              public ZXingAutofocusScannerView(Context context) {
              super(context);
              }


              @Override
              public void setupCameraPreview(CameraWrapper cameraWrapper) {



                  Camera.Parameters parameters= cameraWrapper.mCamera.getParameters();
              if(parameters != null)
              {
              try {
              parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
              cameraWrapper.mCamera.setParameters(parameters);
              }catch (Exception e)
              {
              fallbackFocus = true ;
              }
              // cameraWrapper.mCamera.getParameters()

              }


              super.setupCameraPreview(cameraWrapper);
              }
              @Override
              public void setAutoFocus(boolean state) {
              super.setAutoFocus(callbackFocus);
              }
              }


              Now you must use this class instead ZXingScannerView.



              public class SimpleScannerActivity extends AppCompatActivity implements 
              ZXingAutofocusScannerView.ResultHandler {

              private ZXingAutofocusScannerView mScannerView;

              @Override
              public void onCreate(Bundle state) {
              super.onCreate(state);
              mScannerView = new ZXingAutofocusScannerView(this);
              setContentView(mScannerView);

              @Override
              public void onResume() {
              super.onResume();
              mScannerView.setResultHandler(this);
              mScannerView.startCamera();
              }

              @Override
              public void onPause() {
              super.onPause();
              mScannerView.stopCamera();
              }

              @Override
              public void handleResult(Result rawResult) {
              Toast.makeText(this, ""+rawResult.getText(), Toast.LENGTH_SHORT).show();
              mScannerView.resumeCameraPreview(this);
              }
              }


              If You Use Koltin see this answer :



              class ZXingAutofocusScannerView(context: Context) : 
              ZXingScannerView(context) {
              private val TAG = ZXingAutofocusScannerView::class.qualifiedName

              private var callbackFocus = false

              override fun setupCameraPreview(cameraWrapper: CameraWrapper?) {
              cameraWrapper?.mCamera?.parameters?.let{parameters->
              try {
              parameters.focusMode =
              Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
              cameraWrapper.mCamera.parameters = parameters
              }catch(ex:Exception){
              Log.e(TAG, "Failed to set CONTINOUS_PICTURE", ex)
              callbackFocus = true
              }
              }
              super.setupCameraPreview(cameraWrapper)
              }

              override fun setAutoFocus(state: Boolean) {
              super.setAutoFocus(callbackFocus)
              }
              }





              share|improve this answer




























                3












                3








                3







                I found the answer to this question with help @TeunVR in github.
                You must create a class and extends from ZXingScannerView and Override setupCameraPreview and setAutoFocus .



                public class ZXingAutofocusScannerView extends ZXingScannerView {

                private boolean callbackFocus = false ;

                public ZXingAutofocusScannerView(Context context) {
                super(context);
                }


                @Override
                public void setupCameraPreview(CameraWrapper cameraWrapper) {



                    Camera.Parameters parameters= cameraWrapper.mCamera.getParameters();
                if(parameters != null)
                {
                try {
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                cameraWrapper.mCamera.setParameters(parameters);
                }catch (Exception e)
                {
                fallbackFocus = true ;
                }
                // cameraWrapper.mCamera.getParameters()

                }


                super.setupCameraPreview(cameraWrapper);
                }
                @Override
                public void setAutoFocus(boolean state) {
                super.setAutoFocus(callbackFocus);
                }
                }


                Now you must use this class instead ZXingScannerView.



                public class SimpleScannerActivity extends AppCompatActivity implements 
                ZXingAutofocusScannerView.ResultHandler {

                private ZXingAutofocusScannerView mScannerView;

                @Override
                public void onCreate(Bundle state) {
                super.onCreate(state);
                mScannerView = new ZXingAutofocusScannerView(this);
                setContentView(mScannerView);

                @Override
                public void onResume() {
                super.onResume();
                mScannerView.setResultHandler(this);
                mScannerView.startCamera();
                }

                @Override
                public void onPause() {
                super.onPause();
                mScannerView.stopCamera();
                }

                @Override
                public void handleResult(Result rawResult) {
                Toast.makeText(this, ""+rawResult.getText(), Toast.LENGTH_SHORT).show();
                mScannerView.resumeCameraPreview(this);
                }
                }


                If You Use Koltin see this answer :



                class ZXingAutofocusScannerView(context: Context) : 
                ZXingScannerView(context) {
                private val TAG = ZXingAutofocusScannerView::class.qualifiedName

                private var callbackFocus = false

                override fun setupCameraPreview(cameraWrapper: CameraWrapper?) {
                cameraWrapper?.mCamera?.parameters?.let{parameters->
                try {
                parameters.focusMode =
                Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
                cameraWrapper.mCamera.parameters = parameters
                }catch(ex:Exception){
                Log.e(TAG, "Failed to set CONTINOUS_PICTURE", ex)
                callbackFocus = true
                }
                }
                super.setupCameraPreview(cameraWrapper)
                }

                override fun setAutoFocus(state: Boolean) {
                super.setAutoFocus(callbackFocus)
                }
                }





                share|improve this answer















                I found the answer to this question with help @TeunVR in github.
                You must create a class and extends from ZXingScannerView and Override setupCameraPreview and setAutoFocus .



                public class ZXingAutofocusScannerView extends ZXingScannerView {

                private boolean callbackFocus = false ;

                public ZXingAutofocusScannerView(Context context) {
                super(context);
                }


                @Override
                public void setupCameraPreview(CameraWrapper cameraWrapper) {



                    Camera.Parameters parameters= cameraWrapper.mCamera.getParameters();
                if(parameters != null)
                {
                try {
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                cameraWrapper.mCamera.setParameters(parameters);
                }catch (Exception e)
                {
                fallbackFocus = true ;
                }
                // cameraWrapper.mCamera.getParameters()

                }


                super.setupCameraPreview(cameraWrapper);
                }
                @Override
                public void setAutoFocus(boolean state) {
                super.setAutoFocus(callbackFocus);
                }
                }


                Now you must use this class instead ZXingScannerView.



                public class SimpleScannerActivity extends AppCompatActivity implements 
                ZXingAutofocusScannerView.ResultHandler {

                private ZXingAutofocusScannerView mScannerView;

                @Override
                public void onCreate(Bundle state) {
                super.onCreate(state);
                mScannerView = new ZXingAutofocusScannerView(this);
                setContentView(mScannerView);

                @Override
                public void onResume() {
                super.onResume();
                mScannerView.setResultHandler(this);
                mScannerView.startCamera();
                }

                @Override
                public void onPause() {
                super.onPause();
                mScannerView.stopCamera();
                }

                @Override
                public void handleResult(Result rawResult) {
                Toast.makeText(this, ""+rawResult.getText(), Toast.LENGTH_SHORT).show();
                mScannerView.resumeCameraPreview(this);
                }
                }


                If You Use Koltin see this answer :



                class ZXingAutofocusScannerView(context: Context) : 
                ZXingScannerView(context) {
                private val TAG = ZXingAutofocusScannerView::class.qualifiedName

                private var callbackFocus = false

                override fun setupCameraPreview(cameraWrapper: CameraWrapper?) {
                cameraWrapper?.mCamera?.parameters?.let{parameters->
                try {
                parameters.focusMode =
                Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
                cameraWrapper.mCamera.parameters = parameters
                }catch(ex:Exception){
                Log.e(TAG, "Failed to set CONTINOUS_PICTURE", ex)
                callbackFocus = true
                }
                }
                super.setupCameraPreview(cameraWrapper)
                }

                override fun setAutoFocus(state: Boolean) {
                super.setAutoFocus(callbackFocus)
                }
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 2 at 12:11

























                answered Jan 2 at 10:35









                Abolfazl KalamatiAbolfazl Kalamati

                1518




                1518
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003150%2fhow-to-improve-the-focus-speed-of-camera%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith