【问题标题】:Control the intensity of the flash light in xamain.forms在 xamarin.forms 中控制手电筒的强度
【发布时间】:2016-05-03 07:19:44
【问题描述】:

我是 xamarin 表单的新手。现在正在开发一个用于制作 Torch 的示例应用程序。我有一个用于打开/关闭闪光灯的 nuget。 https://github.com/kphillpotts/Xamarin.Plugins/tree/master/Lamp 。但我喜欢控制闪光灯的强度。我尝试使用本机代码,但未能做到。我搜索谷歌但找不到它。有什么办法可以实现它。

提前谢谢你

【问题讨论】:

    标签: c# visual-studio xamarin xamarin.android xamarin.forms


    【解决方案1】:

    我不知道实现它的插件。但是您可以轻松扩展灯插件。

    你可以扩展界面ILamp像

    public interface ILamp
    {
        ///....
        void TurnOn(float intensity);
    }
    

    然后通过复制TurnOn 功能来实现它

    iOS

    public void TurnOn(float intensity)
    {
        var captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
        if (captureDevice == null)
        {
          Debug.WriteLine("No captureDevice - this won't work on the simulator, try a physical device");
          return;
        }
    
        NSError error = null;
        captureDevice.LockForConfiguration(out error);
        if (error != null)
        {
          Debug.WriteLine(error);
          captureDevice.UnlockForConfiguration();
          return;
        }
        else
        {
          if (captureDevice.TorchMode != AVCaptureTorchMode.On)
          {
            captureDevice.TorchMode = AVCaptureTorchMode.On;
            NSError err;
            captureDevice.SetTorchModeLevel(intensity, out err); // add this line
          }
          captureDevice.UnlockForConfiguration();
        }
    }
    

    在 Android 上,我不确定是否有 API 可以控制它。我找不到一个。如果有,请像在 iOS 上一样继续。

    如果平台没有API,实现TurnOn(float intensity)就好了

    public void TurnOn(float intensity)
    {
        TurnOn();       
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-28
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-13
      • 1970-01-01
      相关资源
      最近更新 更多