【问题标题】:Control the intensity of the flash light in xamain.forms在 xamarin.forms 中控制手电筒的强度
【发布时间】:2016-05-03 07:19:44
【问题描述】:
【问题讨论】:
标签:
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();
}