开发者

Monodroid camera + preview

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);
        }
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜