简体   繁体   English

ZXing on Android:如何将相机设置为负模式?

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

I want to use zxing in an android project. 我想在Android项目中使用zxing。 I have download the code and the example app is running now (ZXingTestActivity). 我已下载代码,示例应用程序正在运行(ZXingTestActivity)。 For your information, i am not very familiar with coding native android. 为了您的信息,我不熟悉编码本机android。

I want to use zxing to scan qr-codes to configurate an application. 我想使用zxing扫描qr代码来配置应用程序。 To avoid confusion between normal qrcodes and configuration qrcodes i want to print inverted/negative qrcodes on screen or paper. 为避免普通qrcode和配置qrcode之间的混淆,我想在屏幕或纸张上打印反转/负qrcode。

To be able to scan these inverted/negative qrcodes, the camera must be in negative mode. 为了能够扫描这些反转/负qrcodes,相机必须处于负模式。 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: 在ZXingTestActivity.java中有一个clicklistener,它为IntentIntegrator指定一些额外的参数,例如:

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? 是否可以使用addExtra添加相机设置以及如何格式化? Is it possible? 可能吗? Or is there another way to configurate the camera to inverted/negative mode? 或者是否有另一种方法将相机配置为反转/反转模式?

I do not know if it completely impossible with ZXing but with ZBar it is possible! 我不知道ZXing是否完全不可能,但ZBar是可能的!

  1. First download the ZBar android version on sourceforge: http://sourceforge.net/projects/zbar/files/AndroidSDK/ 首先在sourceforge上下载ZBar android版本: http : //sourceforge.net/projects/zbar/files/AndroidSDK/

  2. Add project to eclipse 将项目添加到Eclipse

  3. Open CameraPreview.java 打开CameraPreview.java

  4. Add a private var to the class: 向该类添加一个私有变量:

    private Camera.Parameters mCameraParams; 私人Camera.Parameters mCameraParams;

  5. Add the following lines after the line: mCamera = camera; 在行之后添加以下行: mCamera = camera; in the constructor CameraPreview: 在构造函数CameraPreview中:

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

  6. That's it! 而已! (run the project) (运行项目)

Also think that ZBar is faster to detect damaged barcodes. 还认为ZBar可以更快地检测损坏的条形码。 Is the same as the PC-version i have used in another project and does the job very well. 与我在另一个项目中使用的PC版本相同,并且可以很好地完成工作。 Blink with your eyes and the code is there. 眨眼睛,代码在那里。 No fancy things at all, just good! 根本没有花哨的东西,只是很好!

@Erwinus, here's the code. @Erwinus,这是代码。 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. 更多的作业和更少的指责使SO成为一个快乐的地方。

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

Sorry there's not a way to do this via Intent . 抱歉,无法通过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. 不难,但是需要一些代码和CPU周期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM