How to improve the focus speed of camera?
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?

add a comment |
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?

add a comment |
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?

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?


edited Jan 2 at 12:12
MaHDi
777
777
asked Jan 2 at 8:14


Abolfazl KalamatiAbolfazl Kalamati
1518
1518
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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)
}
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
}
}
add a comment |
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)
}
}
add a comment |
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)
}
}
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)
}
}
edited Jan 2 at 12:11
answered Jan 2 at 10:35


Abolfazl KalamatiAbolfazl Kalamati
1518
1518
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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