我正在使用Xamarin开发一个Android应用程序。我必须用手机捕捉一些二维码。当用户点击屏幕时,相机必须执行自动对焦。
有我的代码:
public class MainActivity
{
TextureView _textureView;
Camera _camera;
protected override void OnCreate(Bundle bundle)
{
_camera = Camera.Open();
_textureView = FindViewById<TextureView>(Resource.Id.previewView);
_textureView.SurfaceTextureListener = this;
_textureView.Click += new EventHandler(clickFocus);
}
private void clickFocus(object sender, EventArgs e)
{
try
{
_camera.AutoFocus(this);
}
catch (Exception ex)
{
}
}
}
关于其他课程:
private void _mainactivity_onFocus(object sender, EventArgs e)
{
bool focus = (bool)sender;
if (!focus)
{
Activity.RunOnUiThread(() =>
{
// _ma is the MainActivity
Toast.MakeText(_ma, Resource.String.camerafocusfailed, ToastLength.Short).Show();
});
}
}
我尝试使用Nexus 5,这段代码效果很好。但是对于索尼Xperia Z3紧凑型,总会出现错误camerafocusfailed
我该怎么办?
答案 0 :(得分:0)
虽然我不确定你怎么能把发送者强制推拿......你可以试着找出相机是否支持自动对焦。
var autoFocus = PackageManager.HasSystemFeature("android.hardware.camera.autofocus");