首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过zxing库扫描条形码时如何打开闪光灯?

通过zxing库扫描条形码时如何打开闪光灯?
EN

Stack Overflow用户
提问于 2015-11-25 16:53:27
回答 3查看 4.5K关注 0票数 0

我无法在我的应用程序中找到一个解决方案,即当我使用zxing库意图集成器类扫描条形码时,如何打开闪光灯。扫描条形码如下。

代码语言:javascript
复制
    public void scanNow() {
    IntentIntegrator integrator = new IntentIntegrator(getActivity());
    integrator.setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES);//ONE_D_COD E_TYPES
    integrator.setPrompt("Scan a barcode");
    Camera cam = Camera.open();
    Camera.Parameters p = cam.getParameters();
    p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
    cam.setParameters(p);
    cam.startPreview();
    integrator.setScanningRectangle(10, 10);
    integrator.setResultDisplayDuration(0);
    integrator.setWide(); // Wide scanning rectangle, may work better for 1D barcodes
    integrator.setCameraId(0);
    ;        // Use a specific camera of the device
    integrator.initiateScan();
    }

请给我解决方案,以便我可以实现这一点。谢谢

EN

回答 3

Stack Overflow用户

发布于 2015-11-25 17:22:42

有一个叫做setTorch(Camera.Parameters parameters,boolean on)的方法,您可以在这里找到CameraConfigurationUtils.java

我还没测试过呢。希望它能帮上忙

票数 0
EN

Stack Overflow用户

发布于 2016-02-11 15:14:54

如果您实现了Zxing扫描仪(https://github.com/zxing/zxing),那么在MainActivity.cs文件中有以下激活闪存的方法:

zxingOverlay按钮;查看按钮;

代码语言:javascript
复制
        buttonScanCustomView = this.FindViewById<Button>(Resource.Id.buttonScanCustomView);
        buttonScanCustomView.Click += async delegate {

            //Tell our scanner we want to use a custom overlay instead of the default
            scanner.UseCustomOverlay = true;

            //Inflate our custom overlay from a resource layout
            zxingOverlay = LayoutInflater.FromContext(this).Inflate(Resource.Layout.ZxingOverlay, null);

            //Find the button from our resource layout and wire up the click event
            flashButton = zxingOverlay.FindViewById<Button>(Resource.Id.buttonZxingFlash);
            flashButton.Click += (sender, e) => scanner.ToggleTorch();

            //Set our custom overlay
            scanner.CustomOverlay = zxingOverlay;

            //Start scanning!
            var result = await scanner.Scan();

            HandleScanResult(result);
        };
票数 0
EN

Stack Overflow用户

发布于 2017-04-19 17:11:25

我建议您使用CompoundBarcodeView实例。然后只需调用setTorchOn()和setTorchOff()来打开或关闭flashLight。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33912057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档