Monodroid 相机 +预览
请有人帮助我。我尝试转换 http://drobosson.blogspot。 com/2011/01/google-android-camera-preview-data.html 和 http://marakana.com/forums/android/examples/39.html 到 Monodroid (C#) 但没有成功。我已按照说明进行操作(据我所知),但我不知道如何预览相机(我什至还没有拍照)。
这是我当前的代码 - 它在 Android.Hardware.Camera.Open() 方法上失败,并出现 Java.Lang.RuntimeException (Stacktrace 说“在 Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod) [0x00000] in :0 at Android.Hardware.Camera.Open()...")
我已在清单中添加了相机权限。
代码:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.CameraPage);
_surfaceView = FindViewById<SurfaceView>(Resource.Id.imgCapture);
_debug = FindViewById<TextView>(Resource.Id.lblCameraDebug);
try
{
_camera = Android.Hardware.Camera.Open();
//Android.Hardware.Camera.Parameters camparam = _camera.GetParameters();
//camparam.SetPreviewSize(_surfaceView.Width, _surfaceView.Height);
//_camera.SetParameters(camparam);
//_camera.SetPreviewDisplay(_surfaceView.Holder);
//_camera.StartPreview();
}
catch(Exception ex)
{
_debug.Text = string.Format("Error: {0} - StackTrace: {1}", ex.Message,ex.StackTrace);
}
}
Please someone help me. I have tried to convert http://drobosson.blogspot.com/2011/01/google-android-camera-preview-data.html and http://marakana.com/forums/android/examples/39.html to Monodroid (C#) and have had no success. I have followed the instructions (as far as I can see) and I do not know how to preview the camera (I am not even on taking a PICTURE yet).
Here is my current code - it fails on the Android.Hardware.Camera.Open() method with a Java.Lang.RuntimeException (Stacktrace says "at Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod) [0x00000] in :0 at Android.Hardware.Camera.Open()...")
I have added the camera permission in the manifest.
Code:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.CameraPage);
_surfaceView = FindViewById<SurfaceView>(Resource.Id.imgCapture);
_debug = FindViewById<TextView>(Resource.Id.lblCameraDebug);
try
{
_camera = Android.Hardware.Camera.Open();
//Android.Hardware.Camera.Parameters camparam = _camera.GetParameters();
//camparam.SetPreviewSize(_surfaceView.Width, _surfaceView.Height);
//_camera.SetParameters(camparam);
//_camera.SetPreviewDisplay(_surfaceView.Holder);
//_camera.StartPreview();
}
catch(Exception ex)
{
_debug.Text = string.Format("Error: {0} - StackTrace: {1}", ex.Message,ex.StackTrace);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
https://github.com/xamarin/monodroid-samples /blob/master/ApiDemo/Graphics/CameraPreview.cs
这清除了大部分内容。这是一个起点,而不是解决方案。
它不能解决:
1. 旋转/方向(但这应该在参数中)
2. 使用 axml 将其放到表单元素上(不是作为整个页面)
3.拍照。
https://github.com/xamarin/monodroid-samples/blob/master/ApiDemo/Graphics/CameraPreview.cs
This clears most of it up. It's a starting point, not a solution.
It does NOT solve:
1. Rotation / Orientation (but that should be in the parameters)
2. Getting it onto a form element using axml (not as an entire page)
3. Taking a picture.