Android相機的閃關燈

目錄

Camera1中調節閃關燈代碼

     <uses-permission android:name="android.permission.CAMERA" />
     <uses-feature android:name="android.hardware.camera" />
     <uses-permission android:name="android.permission.FLASHLIGHT"/>

    /**
     * 
     *
     * @param cameraFlashlight
     */
    public void setCameraFlashlight(String cameraFlashlight) {
        if (mCamera != null) {
            try {
                Camera.Parameters param = mCamera.getParameters();
                param.setFlashMode(cameraFlashlight);
                mCamera.setParameters(param);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

常用參數

        /**
         * Flash will not be fired.
         */
        public static final String FLASH_MODE_OFF = "off";

        /**
         * Flash will be fired automatically when required. The flash may be fired
         * during preview, auto-focus, or snapshot depending on the driver.
         */
        public static final String FLASH_MODE_AUTO = "auto";

        /**
         * Flash will always be fired during snapshot. The flash may also be
         * fired during preview or auto-focus depending on the driver.
         */
        public static final String FLASH_MODE_ON = "on";

        /**
         * Flash will be fired in red-eye reduction mode.
         */
        public static final String FLASH_MODE_RED_EYE = "red-eye";

        /**
         * Constant emission of light during preview, auto-focus and snapshot.
         * This can also be used for video recording.
         */
        public static final String FLASH_MODE_TORCH = "torch";

點亮閃光燈:FLASH_MODE_TORCH
關閉閃光燈:FLASH_MODE_OFF
這個兩個參數,足夠實現手電筒的功能。

FLASH_MODE_ON 只有在 takePicture(ShutterCallback shutter, PictureCallback raw, PictureCallback jpeg) 時,纔會點亮閃光燈。

開源庫

手電筒功能

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章