Codebeat
Codebeat

Reputation: 6610

ZXing on Android: how to set camera in negative mode?

I want to use zxing in an android project. I have download the code and the example app is running now (ZXingTestActivity). For your information, i am not very familiar with coding native android.

I want to use zxing to scan qr-codes to configurate an application. To avoid confusion between normal qrcodes and configuration qrcodes i want to print inverted/negative qrcodes on screen or paper.

To be able to scan these inverted/negative qrcodes, the camera must be in negative mode. How can i do this? I am not sure where to start, however....

In the ZXingTestActivity.java there is a clicklistener that specify some extra parameters to the IntentIntegrator, for example:

private final Button.OnClickListener scanProduct = new Button.OnClickListener() {
    @Override
    public void onClick(View v) {
      IntentIntegrator integrator = new IntentIntegrator(ZXingTestActivity.this);
      integrator.addExtra("SCAN_WIDTH", 800);
      integrator.addExtra("SCAN_HEIGHT", 200);
      integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 3000L);
      integrator.addExtra("PROMPT_MESSAGE", "Custom prompt to scan a product");
      integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);
    }
  };

Is it possible to add camera settings with addExtra and how do i format this? Is it possible? Or is there another way to configurate the camera to inverted/negative mode?

Upvotes: 2

Views: 2565

Answers (3)

Sean Owen
Sean Owen

Reputation: 66886

@Erwinus, here's the code. I hope it's now clear why it is something you have already been completely given in previous comments. More homework and fewer accusations makes SO a happy place.

mCameraParams = camera.getParameters();
if (mCameraParams.getSupportedColorEffects().contains(Camera.Parameters.EFFECT_NEGATIVE) {
  mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE);
}
mCamera.setParameters(mCameraParams);

Upvotes: 2

Codebeat
Codebeat

Reputation: 6610

I do not know if it completely impossible with ZXing but with ZBar it is possible!

  1. First download the ZBar android version on sourceforge: http://sourceforge.net/projects/zbar/files/AndroidSDK/

  2. Add project to eclipse

  3. Open CameraPreview.java

  4. Add a private var to the class:

    private Camera.Parameters mCameraParams;

  5. Add the following lines after the line: mCamera = camera; in the constructor CameraPreview:

    mCameraParams = camera.getParameters(); mCameraParams.setColorEffect(Camera.Parameters.EFFECT_NEGATIVE); mCamera.setParameters(mCameraParams);

  6. That's it! (run the project)

Also think that ZBar is faster to detect damaged barcodes. Is the same as the PC-version i have used in another project and does the job very well. Blink with your eyes and the code is there. No fancy things at all, just good!

Upvotes: 4

Sean Owen
Sean Owen

Reputation: 66886

Sorry there's not a way to do this via Intent. A clean patch adding this as an option would be attractive to commit. The only gotcha is that the camera must support the "negative" mode. Then it's trivial (you can see this behavior as a selectable option in Barcode Scanner+). Otherwise you have to flip the image yourself. Not hard, but takes a bit of code and CPU cycles.

Upvotes: 1

Related Questions