ZBar library focus issue
I have integrated ZBar library for QR scanner. But it didn't work perfectly in one of my devices. The camera does not focus automatically on specifically Samsung Galaxy J7+ phone. We have checked in other phones like Motorola, Xiomi, Oneplus and it's working fine.
So can anyone suggest what changes should I make?
Here is my code.
@Override
protected void onStart()
super.onStart();
initCamera();
@Override
protected void onStop()
super.onStop();
releaseCamera();
private void initCamera()
autoFocusHandler = new Handler();
mCamera = getCameraInstance();
/* Instance barcode scanner */
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 1);
scanner.setConfig(0, Config.Y_DENSITY, 1);
scanner.setConfig(0, Config.ENABLE, 0);
// Only enable the codes your app requires
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
CameraPreview mPreview = new CameraPreview(this, mCamera, previewCb, getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS) ? autoFocusCB : null);
if (mBinding.preview.getChildCount() > 0)
mBinding.preview.removeAllViews();
mBinding.preview.addView(mPreview);
/**
* 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)
e.printStackTrace();
return c;
private void releaseCamera()
if (mCamera != null)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.release();
mCamera = null;
private Runnable doAutoFocus = new Runnable()
public void run()
if (previewing)
mCamera.autoFocus(autoFocusCB);
;
Camera.PreviewCallback previewCb = new Camera.PreviewCallback()
public void onPreviewFrame(byte data, Camera camera)
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms)
final String code = sym.getData();
;
// Mimic continuous auto-focusing
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback()
public void onAutoFocus(boolean success, Camera camera)
autoFocusHandler.postDelayed(doAutoFocus, 1000);
;
android zbar
add a comment |
I have integrated ZBar library for QR scanner. But it didn't work perfectly in one of my devices. The camera does not focus automatically on specifically Samsung Galaxy J7+ phone. We have checked in other phones like Motorola, Xiomi, Oneplus and it's working fine.
So can anyone suggest what changes should I make?
Here is my code.
@Override
protected void onStart()
super.onStart();
initCamera();
@Override
protected void onStop()
super.onStop();
releaseCamera();
private void initCamera()
autoFocusHandler = new Handler();
mCamera = getCameraInstance();
/* Instance barcode scanner */
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 1);
scanner.setConfig(0, Config.Y_DENSITY, 1);
scanner.setConfig(0, Config.ENABLE, 0);
// Only enable the codes your app requires
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
CameraPreview mPreview = new CameraPreview(this, mCamera, previewCb, getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS) ? autoFocusCB : null);
if (mBinding.preview.getChildCount() > 0)
mBinding.preview.removeAllViews();
mBinding.preview.addView(mPreview);
/**
* 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)
e.printStackTrace();
return c;
private void releaseCamera()
if (mCamera != null)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.release();
mCamera = null;
private Runnable doAutoFocus = new Runnable()
public void run()
if (previewing)
mCamera.autoFocus(autoFocusCB);
;
Camera.PreviewCallback previewCb = new Camera.PreviewCallback()
public void onPreviewFrame(byte data, Camera camera)
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms)
final String code = sym.getData();
;
// Mimic continuous auto-focusing
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback()
public void onAutoFocus(boolean success, Camera camera)
autoFocusHandler.postDelayed(doAutoFocus, 1000);
;
android zbar
add a comment |
I have integrated ZBar library for QR scanner. But it didn't work perfectly in one of my devices. The camera does not focus automatically on specifically Samsung Galaxy J7+ phone. We have checked in other phones like Motorola, Xiomi, Oneplus and it's working fine.
So can anyone suggest what changes should I make?
Here is my code.
@Override
protected void onStart()
super.onStart();
initCamera();
@Override
protected void onStop()
super.onStop();
releaseCamera();
private void initCamera()
autoFocusHandler = new Handler();
mCamera = getCameraInstance();
/* Instance barcode scanner */
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 1);
scanner.setConfig(0, Config.Y_DENSITY, 1);
scanner.setConfig(0, Config.ENABLE, 0);
// Only enable the codes your app requires
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
CameraPreview mPreview = new CameraPreview(this, mCamera, previewCb, getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS) ? autoFocusCB : null);
if (mBinding.preview.getChildCount() > 0)
mBinding.preview.removeAllViews();
mBinding.preview.addView(mPreview);
/**
* 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)
e.printStackTrace();
return c;
private void releaseCamera()
if (mCamera != null)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.release();
mCamera = null;
private Runnable doAutoFocus = new Runnable()
public void run()
if (previewing)
mCamera.autoFocus(autoFocusCB);
;
Camera.PreviewCallback previewCb = new Camera.PreviewCallback()
public void onPreviewFrame(byte data, Camera camera)
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms)
final String code = sym.getData();
;
// Mimic continuous auto-focusing
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback()
public void onAutoFocus(boolean success, Camera camera)
autoFocusHandler.postDelayed(doAutoFocus, 1000);
;
android zbar
I have integrated ZBar library for QR scanner. But it didn't work perfectly in one of my devices. The camera does not focus automatically on specifically Samsung Galaxy J7+ phone. We have checked in other phones like Motorola, Xiomi, Oneplus and it's working fine.
So can anyone suggest what changes should I make?
Here is my code.
@Override
protected void onStart()
super.onStart();
initCamera();
@Override
protected void onStop()
super.onStop();
releaseCamera();
private void initCamera()
autoFocusHandler = new Handler();
mCamera = getCameraInstance();
/* Instance barcode scanner */
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 1);
scanner.setConfig(0, Config.Y_DENSITY, 1);
scanner.setConfig(0, Config.ENABLE, 0);
// Only enable the codes your app requires
scanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
CameraPreview mPreview = new CameraPreview(this, mCamera, previewCb, getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS) ? autoFocusCB : null);
if (mBinding.preview.getChildCount() > 0)
mBinding.preview.removeAllViews();
mBinding.preview.addView(mPreview);
/**
* 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)
e.printStackTrace();
return c;
private void releaseCamera()
if (mCamera != null)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.release();
mCamera = null;
private Runnable doAutoFocus = new Runnable()
public void run()
if (previewing)
mCamera.autoFocus(autoFocusCB);
;
Camera.PreviewCallback previewCb = new Camera.PreviewCallback()
public void onPreviewFrame(byte data, Camera camera)
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0)
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms)
final String code = sym.getData();
;
// Mimic continuous auto-focusing
Camera.AutoFocusCallback autoFocusCB = new Camera.AutoFocusCallback()
public void onAutoFocus(boolean success, Camera camera)
autoFocusHandler.postDelayed(doAutoFocus, 1000);
;
android zbar
android zbar
asked Nov 13 '18 at 10:09
Gaurav BalbhadraGaurav Balbhadra
1419
1419
add a comment |
add a comment |
0
active
oldest
votes
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%2f53278572%2fzbar-library-focus-issue%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53278572%2fzbar-library-focus-issue%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