简体   繁体   English

Android Camera2 API Flash 不适用于 Galaxy 设备

[英]Android Camera2 API Flash doesnt work on galaxy devices

I am using the Android Camera2 API to take photos for an app and I can't get the flash to work properly on most Samsung Galaxy devices (galaxy s6 edge, galaxy s7, galaxy j7).我正在使用 Android Camera2 API 为应用程序拍照,但在大多数三星 Galaxy 设备(galaxy s6 edge、galaxy s7、galaxy j7)上,我无法让闪光灯正常工作。 I believe I have implemented the flash logic properly because Google's Camera app that used to be on the Play Store also exhibits the same behaviors.我相信我已经正确实现了 flash 逻辑,因为曾经在 Play 商店中的 Google 相机应用程序也表现出相同的行为。 Also the galaxy s8 seems to work with the flash pretty well (although results definitely have inconsistent lighting)此外,galaxy s8 似乎与闪光灯配合得很好(尽管结果肯定会出现不一致的照明)

The issue with the galaxy j7 is that when I take a picture with flash (either with flash locked on or with auto flash in a scene that requires flash) the flash will stay on for a long time, the preview will lock, and then after maybe 7 seconds the image will take, and the flash is not a part of the image. Galaxy j7的问题是,当我用闪光灯拍照时(闪光灯锁定或在需要闪光灯的场景中使用自动闪光灯)闪光灯会保持很长时间,预览会锁定,然后图像可能需要 7 秒,而闪光灯不是图像的一部分。

I have the following method handling flash modes:我有以下处理闪光模式的方法:

private void setAutoFlash(CaptureRequest.Builder requestBuilder)
{
    switch (mFlashState)
    {
        case FLASH_STATE_AUTO:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
            //requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
            break;
        case FLASH_STATE_ON:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
            //requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);
            break;
        case FLASH_STATE_OFF:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
            //requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
            break;
    }
}

This flash logic is called every time a CaptureRequest.Builder is needed每次需要 CaptureRequest.Builder 时都会调用此闪存逻辑

The 3 commented out lines are something else I read that was suggested to help flash work properly for me, but it doesn't seem to do anything注释掉的 3 行是我读过的其他内容,建议帮助 Flash 为我正常工作,但它似乎没有做任何事情

Samsung has their own camera API ( http://developer.samsung.com/galaxy/camera ) but I read that it is just a wrapper over Camera2 and I am worried that their API won't even fix my issue.三星有自己的相机 API ( http://developer.samsung.com/galaxy/camera ),但我读到它只是 Camera2 的包装器,我担心他们的 API 甚至无法解决我的问题。

Additional Information:附加信息:

  • I have tried some camera apps from the play store, some work and others don't.我尝试过 Play 商店中的一些相机应用程序,有些工作,有些则没有。
  • ZCamera works fine with flash, which made me think they use Samsungs camera API to get it working, but then I noticed that ZCamera's touch metering doesn't work on Samsung devices which is another issue I came across while debugging my Camera2 implementation. ZCamera 与闪光灯配合得很好,这让我觉得他们使用三星的相机 API 来让它工作,但后来我注意到 ZCamera 的触摸测光在三星设备上不起作用,这是我在调试 Camera2 实现时遇到的另一个问题。
  • Flash seems to work fine if I stick with the deprecated Camera API如果我坚持使用已弃用的 Camera API,Flash 似乎可以正常工作

Any help on how to accomplish a working flash would be greatly appreciated任何有关如何完成工作闪光的帮助将不胜感激

Actually using camera2 API is very special in android devices.实际上在android设备中使用camera2 API是非常特殊的。 Some methods may not be implemented.有些方法可能无法实现。 For example: this and this .例如: thisthis For the others, proper flash modes should be set depends on the other properties.对于其他人,应根据其他属性设置适当的闪光模式。 This code works for me in most Samsung devices that support camera2API:此代码适用于大多数支持 camera2API 的三星设备:

 if (mIsFlashSupported) {
        switch (mFlashMode) {
            case FLASH_MODE_ON:
                requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
                requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
                requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_FLUORESCENT);
                break;

            case FLASH_MODE_OFF:
                requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
                requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
                requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_DAYLIGHT);
                break;

            case FLASH_MODE_AUTO:
            default:
                requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
                requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
                requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_DAYLIGHT);
                break;
        }
    }

After working at this on and off for a bit I realized a few things.在断断续续地工作之后,我意识到了一些事情。 I mentioned that ZCamera (from the play store) works with flash, and I thought they accomplished this by using the Samsung SDK.我提到 ZCamera(来自 Play 商店)与 Flash 配合使用,我认为他们通过使用三星 SDK 实现了这一点。 I checked the app and it does not use the Samsung SDK.我检查了该应用程序,它没有使用三星 SDK。

I also incorporated the Samsung SDK into my app and that didn't change anything.我还将三星 SDK 合并到我的应用程序中,但没有任何改变。 The Samsung SDK is really just a wrapper around google's camera 2 so you can add some Samsung specific features, adding it to your project wont fix any Samsung compatibilities.三星 SDK 实际上只是 google 相机 2 的包装器,因此您可以添加一些三星特定功能,将其添加到您的项目中不会修复任何三星兼容性。

What I finally realized was that the touch metering flow I had programmed myself (touch to focus/then take a photo) worked very differently than my logic that ran when we take a photo without touch to focus.我最终意识到的是,我自己编程的触摸测光流程(触摸对焦/然后拍照)与我们在没有触摸对焦的情况下拍照时运行的逻辑非常不同。 The regular photo logic was borrowed from googles camera2 api example code and it wasnt working propery.常规照片逻辑是从 googles camera2 api 示例代码中借来的,它无法正常工作。

The trick to get the flash to fire on Samsung devices (or at least what worked for me) was to first trigger a check for AE levels, and once that converges then start the auto focus trigger.让闪光灯在三星设备(或至少对我有用)上闪光的技巧是首先触发对 AE 级别的检查,一旦收敛,然后启动自动对焦触发器。 If flash is turned on this will fire the flash to check AE levels and to focus, and then fire the flash once more to take the photo如果打开闪光灯,这将闪光以检查 AE 级别和对焦,然后再次闪光以拍照

My application takes a photo every 5 seconds.我的应用程序每 5 秒拍一张照片。 I (1) select the camera, (2) acquirer a session and then with each loop I (3) create a Capture request in which I set the Flash Mode and call the capture method on the session.我 (1) 选择相机,(2) 获取一个会话,然后在每个循环中我 (3) 创建一个捕获请求,在其中设置 Flash 模式并在会话上调用捕获方法。

I have no issues with my Samsung SM-G550T (Android version 6.01), but I was having some issues with the Flash Mode on my Moto G4 (Android version 7.0).我的三星 SM-G550T(Android 6.01 版)没有问题,但我的 Moto G4(Android 7.0 版)的 Flash 模式有问题。 I got both phones to Flash, but only with this setting:我将两部手机都设置为 Flash,但仅限于以下设置:

CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);

I am presently having an issue with a LG device (M210N) (Android version 7.0).我目前在使用 LG 设备 (M210N)(Android 7.0 版)时遇到问题。 Using the settings I stated above I get the device to flash just once .使用我上面提到的设置,我让设备只闪烁一次 If I completely re-initialize the camera (as described above) the device will flash again only once.如果我完全重新初始化相机(如上所述),设备只会再次闪烁一次。

If I add the CONTROL_AE_MODE_ON_ALWAYS_FLASH setting to the above requestBuilder, then the LG does not flash at all.如果我将CONTROL_AE_MODE_ON_ALWAYS_FLASH设置添加到上述 requestBuilder 中,那么 LG 根本不会闪烁。 So I had to remove that flag.所以我不得不移除那个标志。

I have tried many different additional settings and combination for settings and none of them have eliminated this issue.我尝试了许多不同的附加设置和设置组合,但没有一个能消除这​​个问题。 I wonder how many devices are affected by this issue.我想知道有多少设备受到此问题的影响。

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

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