第37讲 Android Camera2 API 拍照打闪实战

本讲是Android Camera专题系列的第37讲,我们介绍Android Camera2 API专题的拍照打闪实战,包括如下内容:

  1. 设置不同的Flash模式
  2. 拍照打闪流程

视频在线观看:

加入知识星球与更多Camera同学交流
– 星球名称:深入浅出Android Camera
– 星球ID: 17296815

GeekCamera2 设置不同的Flash模式

CameraController2#CameraSettings#setAEMode

switch(flash_value) {
    case "flash_off":
        builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
        builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
        break;
    case "flash_auto":
        // note we set this even in fake flash mode (where we manually turn torch on and off to simulate flash) so we
        // can read the FLASH_REQUIRED state to determine if flash is required
    /*if( use_fake_precapture || CameraController2.this.want_expo_bracketing )
        builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
    else*/
        builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH);
        builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
        break;
    case "flash_on":
        // see note above for "flash_auto" for why we set this even fake flash mode - arguably we don't need to know
        // about FLASH_REQUIRED in flash_on mode, but we set it for consistency...
    /*if( use_fake_precapture || CameraController2.this.want_expo_bracketing )
        builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
    else*/
        builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
        builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
        break;
    case "flash_torch":
        builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
        builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
        break;
    case "flash_red_eye":
        // not supported for expo bracketing or burst
        if( CameraController2.this.burst_type != BurstType.BURSTTYPE_NONE )
            builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
        else
            builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE);
        builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
        break;
    case "flash_frontscreen_auto":
    case "flash_frontscreen_on":
    case "flash_frontscreen_torch":
        builder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
        builder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
        break;
}

GeekCamera2 拍照打闪流程

  1. 触发precapture

    CameraController2#runPrecapture

  2. 等待precapture完成

    CameraController2#handleStateChange

  3. 拍照

    CameraController2#takePictureAfterPrecapture

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

deepinout_camera

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值