Пример #1
0
        /// <summary>
        /// Turn the lamp on
        /// </summary>
        public async void TurnOn()
        {
            // further information about accessing the camera light can be found here:
            // http://developer.nokia.com/community/wiki/Using_the_camera_light_in_Windows_Phone_7,_8_and_8.1

            if (_avDevice == null)
            {
                _avDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back,
                                                                    AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First());
            }

            // turn flashlight on
            var supportedCameraModes = AudioVideoCaptureDevice
                                       .GetSupportedPropertyValues(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.VideoTorchMode);

            if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
            {
                _avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);

                // set flash power to maxinum
                _avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
                                      AudioVideoCaptureDevice.GetSupportedPropertyRange(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
            }
            else
            {
                Debug.WriteLine("Torch Mode not supported by this device");
            }
        }
Пример #2
0
 private void ToggleFlash()
 {
     try
     {
         IReadOnlyList <object> supportedCameraModes =
             AudioVideoCaptureDevice.GetSupportedPropertyValues(_sensorLocation,
                                                                KnownCameraAudioVideoProperties.VideoTorchMode);
         //ToDo Don't like this line. Simplify....
         if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
         {
             if (!_flashOn)
             {
                 _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                 _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
                                            AudioVideoCaptureDevice.GetSupportedPropertyRange(_sensorLocation,
                                                                                              KnownCameraAudioVideoProperties
                                                                                              .VideoTorchPower)
                                            .Max);
                 _contentGrid.Background = new SolidColorBrush(Colors.White);
                 _flashOn = true;
             }
             else
             {
                 _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
                 _contentGrid.Background = null;
                 _flashOn = false;
             }
         }
     }
     catch (Exception ex)
     {
         _shakeStatusTextBlock.Text = "The flash cannot be controlled on this device.";
     }
 }
Пример #3
0
        private void ToggleFlash()
        {
            IReadOnlyList <object> supportedCameraModes =
                AudioVideoCaptureDevice.GetSupportedPropertyValues(_sensorLocation,
                                                                   KnownCameraAudioVideoProperties.VideoTorchMode);

            if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
            {
                if (!_flashOn)
                {
                    _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                    _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
                                               AudioVideoCaptureDevice.GetSupportedPropertyRange(_sensorLocation,
                                                                                                 KnownCameraAudioVideoProperties
                                                                                                 .VideoTorchPower)
                                               .Max);
                    _flashOn = true;
                }
                else
                {
                    _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
                    _flashOn = false;
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Here's where the magic happens.
        /// </summary>
        private void ToggleFlash()
        {
            try
            {
                var vibrator = VibrateController.Default;

                var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(SensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);

                if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
                {
                    if (!_flashOn)
                    {
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower, AudioVideoCaptureDevice.GetSupportedPropertyRange(SensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);

                        if (_appSettings.EnableSoundSetting)
                        {
                            SoundEffects.PlaySound(new Uri(soundOn, UriKind.Relative));
                        }

                        if (_appSettings.EnableVibrateSetting && vibrator != null)
                        {
                            vibrator.Start(new TimeSpan(0, 0, 0, 0, 20));
                        }

                        TorchButton.Background = _torchOnImage;

                        _flashOn = true;
                    }
                    else
                    {
                        _captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);

                        if (_appSettings.EnableSoundSetting)
                        {
                            SoundEffects.PlaySound(new Uri(soundOff, UriKind.Relative));
                        }

                        if (_appSettings.EnableVibrateSetting && vibrator != null)
                        {
                            vibrator.Start(new TimeSpan(0, 0, 0, 0, 10));
                        }

                        TorchButton.Background = _torchOffImage;

                        _flashOn = false;
                    }
                }
            }
            catch (Exception ex)
            {
                DebugText.Text = ex.Message;
            }

            // Update battery icon
            SetBatteryIcon();
        }
Пример #5
0
 static public void Enable()
 {
     try
     {
         if (isExist)
         {
             CamVideo.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
         }
     }
     catch
     {
     }
 }
        private void OnPhotoCameraInitialized(object sender, CameraOperationCompletedEventArgs e)
        {
            MobileBarcodeScanner.Log("Initialized Camera");

            if (_photoCamera == null)
            {
                return;
            }

            MobileBarcodeScanner.Log("Creating Luminance Source");

            var width  = Convert.ToInt32(_photoCamera.PreviewResolution.Width);
            var height = Convert.ToInt32(_photoCamera.PreviewResolution.Height);

            _luminance = new PhotoCameraLuminanceSource(width, height);

            var supportedCameraModes = AudioVideoCaptureDevice.GetSupportedPropertyValues(_photoCamera.SensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);

            if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
            {
                _photoCamera.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
            }

            _initialized = true;

            MobileBarcodeScanner.Log("Luminance Source Created");

            OnCameraInitialized(_initialized);
        }
 private void ToggleFlash_Click(object sender, RoutedEventArgs e)
 {
     if (flashSupported)
     {
         if (flashOn)
         {
             captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
             flashImage.Source = App.Current.Resources["flash"] as BitmapImage;
         }
         else
         {
             captureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
             flashImage.Source = App.Current.Resources["flashPressed"] as BitmapImage;
         }
         flashOn = !flashOn;
     }
 }
Пример #8
0
        private async void TurnFlashOn()
        {
            if (_avDevice == null)
            {
                SetupFlash();
            }

            try
            {
                _avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);

                _lightOn      = true;
                PictureSource = "/onresized.png";
            }
            catch (Exception ex)
            {
            }
        }
Пример #9
0
 public static void TurnOffFlashlight(ToggleButton flashlight, AudioVideoCaptureDevice avDevice)
 {
     try
     {
         avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.Off);
         flashlight.IsChecked = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Turn Off Flashlight " + ex.Message);
     }
 }
Пример #10
0
        public static void TurnOnFlashlight(ToggleButton flashlight, AudioVideoCaptureDevice avDevice,
                                            CameraSensorLocation sensorLocation)
        {
            try
            {
                IReadOnlyList <object> supportedCameraModes =
                    AudioVideoCaptureDevice.GetSupportedPropertyValues(sensorLocation,
                                                                       KnownCameraAudioVideoProperties.VideoTorchMode);

                if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
                {
                    avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
                    // set flash power to maxinum
                    avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
                                         AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation,
                                                                                           KnownCameraAudioVideoProperties.VideoTorchPower).Max);
                }
                flashlight.IsChecked = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Turn On Flashlight " + ex.Message);
            }
        }
        private async void StartInternal()
        {
            var locations = GetCameraSensorLocations();
            var location  = locations[0];

            if (CaptureArgs.DeviceNumber.HasValue && CaptureArgs.DeviceNumber.Value < locations.Length)
            {
                location = locations[CaptureArgs.DeviceNumber.Value];
            }
            else if (DesiredDeviceNumber.HasValue && DesiredDeviceNumber.Value < locations.Length)
            {
                location     = locations[DesiredDeviceNumber.Value];
                DeviceNumber = DesiredDeviceNumber.Value;
            }

            Label = GetCameraSensorLocationName(location);

            Capture = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(location, GetInitialResolution(location, CaptureArgs.Width, CaptureArgs.Height));

            Capture.SetProperty(KnownCameraAudioVideoProperties.VideoFrameRate, CaptureArgs.FrameRate);

            Capture.PreviewFrameAvailable += Capture_PreviewFrameAvailable;
            if (Preview != null)
            {
                Preview.LoadCamera(Capture);
                RunOnUIThread(() =>
                {
                    SetRotation(Page.Orientation);
                    Preview.Rotate(BufferRotate);
                });
            }

            RunOnUIThread(() =>
            {
                XnaTimer          = new DispatcherTimer();
                XnaTimer.Interval = TimeSpan.FromMilliseconds(10);
                XnaTimer.Tick    += XnaTimer_Tick;
                XnaTimer.Start();
            });
        }
Пример #12
0
        private async void VideoRecord_Loaded(object sender, RoutedEventArgs e)
        {
            // 一些概述类的说明
            Summary();

            // 是否有后置摄像头
            if (AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
            {
                // 获取后置摄像头摄像时的可用分辨率
                IReadOnlyList <Windows.Foundation.Size> supportedResolutions = AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);
                Windows.Foundation.Size resolution = supportedResolutions[0];

                try
                {
                    // 让后置摄像头以指定的分辨率捕获镜头内容
                    _captureDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);

                    // AudioVideoCaptureDevice.OpenForVideoOnlyAsync() - 仅捕获视频
                    // AudioVideoCaptureDevice.OpenForAudioOnlyAsync() - 仅捕获音频

                    // 录像失败时触发的事件
                    _captureDevice.RecordingFailed += _captureDevice_RecordingFailed;


                    /*
                     * SetCaptureResolutionAsync() - 设置摄像的分辨率
                     * CaptureResolution - 获取当前摄像的分辨率
                     * VideoEncodingFormat - 当前的视频编码格式
                     * AudioEncodingFormat - 当前的音频编码格式
                     * FocusRegion - 对焦区域
                     * SensorLocation - 当前摄像头的位置(CameraSensorLocation 枚举:Back 或 Front)
                     * SensorRotationInDegrees - 获取摄像头传感器相对于屏幕的旋转度数
                     * FocusAsync() - 自动对焦
                     * ResetFocusAsync() - 复位对焦
                     */


                    /*
                     * KnownCameraAudioVideoProperties 属性集包括
                     *     VideoFrameRate - 每秒抓取的视频帧数
                     *     H264EncodingProfile - H264 编码的 profile(H264EncoderProfile 枚举)
                     *     H264EncodingLevel - H264 编码的 level(H264EncoderLevel 枚举)
                     *     H264EnableKeyframes - 是否启用关键帧
                     *     H264QuantizationParameter - QP 值,低的 QP 会保留大部分空间的详细信息,从而达到最佳质量,高的 QP 会在一定程度上造成质量的损失,但能帮助编码器实现较低的比特率
                     *     H264RequestDropNextNFrames - 指定编码器应丢弃的帧数
                     *     H264RequestIdrFrame - 此属性设置为 true 时,系统请求编码流程进行瞬时解码刷新(IDR)
                     *     UnmuteAudioWhileRecording - 此属性设置为 true 时,能在记录期间为音频取消静音
                     *     VideoTorchMode - 录像时如何使用闪光灯(VideoTorchMode 枚举:Off, Auto, On)
                     *     VideoTorchPower - 录像时闪光灯的亮度,无单位且不同设备上的值不同
                     */
                    _captureDevice.SetProperty(KnownCameraAudioVideoProperties.H264EncodingProfile, H264EncoderProfile.Baseline);


                    /*
                     * KnownCameraGeneralProperties 属性集包括
                     *     AutoFocusRange - 自动对焦的范围(AutoFocusRange 枚举,包括微距等)
                     *     EncodeWithOrientation - 视频编码时的旋转角度,必须是 90 的倍数
                     *     SpecifiedCaptureOrientation -  元数据中的旋转角度,必须是 90 的倍数
                     *     IsShutterSoundEnabledByUser - 用户是否启用了快门声音,只读
                     *     IsShutterSoundRequiredForRegion - 运行应用程序的区域是否需要快门声音(有些区域为了保护隐私,要求照相或录像必须要有快门声音),只读
                     *     PlayShutterSoundOnCapture - 指定捕获时是否播放快门声音
                     *     ManualFocusPosition - 手动对焦的位置
                     */
                    _captureDevice.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Normal);
                    _captureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, _captureDevice.SensorRotationInDegrees);


                    // 获取指定属性的值
                    // _captureDevice.GetProperty(KnownCameraGeneralProperties.IsShutterSoundEnabledByUser);

                    /*
                     * 获取指定的范围类属性在当前摄像头中所允许的值的范围
                     */
                    // AudioVideoCaptureDevice.GetSupportedPropertyRange(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.H264QuantizationParameter);

                    /*
                     * 获取指定的值类属性在当前摄像头中所允许的值的列表
                     */
                    // AudioVideoCaptureDevice.GetSupportedPropertyValues(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.H264EncodingProfile);

                    // 实时显示捕获的内容
                    videoBrush.SetSource(_captureDevice); // 扩展方法来自:Microsoft.Devices.CameraVideoBrushExtensions

                    rt.Angle = _captureDevice.SensorRotationInDegrees;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有后置摄像头");
            }
        }
        private async void VideoRecord_Loaded(object sender, RoutedEventArgs e)
        {
            // 一些概述类的说明
            Summary();

            // 是否有后置摄像头
            if (AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
            {
                // 获取后置摄像头摄像时的可用分辨率
                IReadOnlyList<Windows.Foundation.Size> supportedResolutions = AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);
                Windows.Foundation.Size resolution = supportedResolutions[0];

                try
                {
                    // 让后置摄像头以指定的分辨率捕获镜头内容
                    _captureDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);
                    // AudioVideoCaptureDevice.OpenForVideoOnlyAsync() - 仅捕获视频
                    // AudioVideoCaptureDevice.OpenForAudioOnlyAsync() - 仅捕获音频

                    // 录像失败时触发的事件
                    _captureDevice.RecordingFailed += _captureDevice_RecordingFailed;


                    /*
                     * SetCaptureResolutionAsync() - 设置摄像的分辨率
                     * CaptureResolution - 获取当前摄像的分辨率
                     * VideoEncodingFormat - 当前的视频编码格式
                     * AudioEncodingFormat - 当前的音频编码格式
                     * FocusRegion - 对焦区域
                     * SensorLocation - 当前摄像头的位置(CameraSensorLocation 枚举:Back 或 Front)
                     * SensorRotationInDegrees - 获取摄像头传感器相对于屏幕的旋转度数
                     * FocusAsync() - 自动对焦
                     * ResetFocusAsync() - 复位对焦
                     */


                    /*
                     * KnownCameraAudioVideoProperties 属性集包括
                     *     VideoFrameRate - 每秒抓取的视频帧数
                     *     H264EncodingProfile - H264 编码的 profile(H264EncoderProfile 枚举)
                     *     H264EncodingLevel - H264 编码的 level(H264EncoderLevel 枚举)
                     *     H264EnableKeyframes - 是否启用关键帧
                     *     H264QuantizationParameter - QP 值,低的 QP 会保留大部分空间的详细信息,从而达到最佳质量,高的 QP 会在一定程度上造成质量的损失,但能帮助编码器实现较低的比特率
                     *     H264RequestDropNextNFrames - 指定编码器应丢弃的帧数
                     *     H264RequestIdrFrame - 此属性设置为 true 时,系统请求编码流程进行瞬时解码刷新(IDR)
                     *     UnmuteAudioWhileRecording - 此属性设置为 true 时,能在记录期间为音频取消静音
                     *     VideoTorchMode - 录像时如何使用闪光灯(VideoTorchMode 枚举:Off, Auto, On)
                     *     VideoTorchPower - 录像时闪光灯的亮度,无单位且不同设备上的值不同
                     */
                    _captureDevice.SetProperty(KnownCameraAudioVideoProperties.H264EncodingProfile, H264EncoderProfile.Baseline);


                    /*
                     * KnownCameraGeneralProperties 属性集包括
                     *     AutoFocusRange - 自动对焦的范围(AutoFocusRange 枚举,包括微距等)
                     *     EncodeWithOrientation - 视频编码时的旋转角度,必须是 90 的倍数
                     *     SpecifiedCaptureOrientation -  元数据中的旋转角度,必须是 90 的倍数
                     *     IsShutterSoundEnabledByUser - 用户是否启用了快门声音,只读
                     *     IsShutterSoundRequiredForRegion - 运行应用程序的区域是否需要快门声音(有些区域为了保护隐私,要求照相或录像必须要有快门声音),只读
                     *     PlayShutterSoundOnCapture - 指定捕获时是否播放快门声音
                     *     ManualFocusPosition - 手动对焦的位置
                     */
                    _captureDevice.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Normal);
                    _captureDevice.SetProperty(KnownCameraGeneralProperties.EncodeWithOrientation, _captureDevice.SensorRotationInDegrees);


                    // 获取指定属性的值
                    // _captureDevice.GetProperty(KnownCameraGeneralProperties.IsShutterSoundEnabledByUser);

                    /*
                     * 获取指定的范围类属性在当前摄像头中所允许的值的范围
                     */
                    // AudioVideoCaptureDevice.GetSupportedPropertyRange(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.H264QuantizationParameter);

                    /*
                     * 获取指定的值类属性在当前摄像头中所允许的值的列表
                     */
                    // AudioVideoCaptureDevice.GetSupportedPropertyValues(CameraSensorLocation.Back, KnownCameraAudioVideoProperties.H264EncodingProfile);

                    // 实时显示捕获的内容
                    videoBrush.SetSource(_captureDevice); // 扩展方法来自:Microsoft.Devices.CameraVideoBrushExtensions

                    rt.Angle = _captureDevice.SensorRotationInDegrees;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show("没有后置摄像头");
            }
        }
        private async void StartInternal()
        {
            var locations = GetCameraSensorLocations();
            var location = locations[0];
            if (CaptureArgs.DeviceNumber.HasValue && CaptureArgs.DeviceNumber.Value < locations.Length)
            {
                location = locations[CaptureArgs.DeviceNumber.Value];
            }
            else if (DesiredDeviceNumber.HasValue && DesiredDeviceNumber.Value < locations.Length)
            {
                location = locations[DesiredDeviceNumber.Value];
                DeviceNumber = DesiredDeviceNumber.Value;
            }

            Label = GetCameraSensorLocationName(location);

            Capture = await AudioVideoCaptureDevice.OpenForVideoOnlyAsync(location, GetInitialResolution(location, CaptureArgs.Width, CaptureArgs.Height));
            Capture.SetProperty(KnownCameraAudioVideoProperties.VideoFrameRate, CaptureArgs.FrameRate);
           
            Capture.PreviewFrameAvailable += Capture_PreviewFrameAvailable;
            if (Preview != null)
            {
                Preview.LoadCamera(Capture);
                RunOnUIThread(() =>
                {
                    SetRotation(Page.Orientation);
                    Preview.Rotate(BufferRotate);
                });
            }

            RunOnUIThread(() =>
            {
                XnaTimer = new DispatcherTimer();
                XnaTimer.Interval = TimeSpan.FromMilliseconds(10);
                XnaTimer.Tick += XnaTimer_Tick;
                XnaTimer.Start();
            });
        }