小编Nic*_*alo的帖子

Xamarin Android相机流

我正在开发一个项目,我需要创建一个类似于SnapChat的应用程序,我在Visual Studio上使用Xamarin,我想创建一个带有屏幕底部按钮的Camera Stream.一旦用户触摸该圈子该应用程序将拍照!

Snapchat示例

我是xamarin的新手,所以我有很多问题.

1.)我在xamarin页面上关注这个例子:https://developer.xamarin.com/recipes/android/other_ux/textureview/display_a_stream_from_the_camera/

但是我不明白为什么相机流看起来很奇怪,如果手机处于垂直位置,显示的图像是水平的,反之亦然,当我移动手机时,显示的图像移动得非常慢,就好像它会做任何一种调整大小或什么的.

我怎样才能解决这个问题 ?

2.)我需要在应用程序中添加按钮,但代码中包含以下行:

SetContentView (_textureView);  
Run Code Online (Sandbox Code Playgroud)

所以我找到了这段代码:

public class Activity1 : Activity 
{
    bool _previewing;
    Camera _camera;
    TextureView _textureView;
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        SetContentView(Resource.Layout.CameraLayout);
        Button button = FindViewById<Button>(Resource.Id.button1);
        _textureView = FindViewById<TextureView>(Resource.Id.textureView1);
        button.Click += delegate {
            try
            {
                if (!_previewing)
                {
                    _camera = Camera.Open();
                    _camera.SetPreviewTexture(_textureView.SurfaceTexture);
                    _camera.StartPreview();
                }
                else
                {
                    _camera.StopPreview();
                    _camera.Release();
                }
            }
            catch (Java.IO.IOException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                _previewing = !_previewing;
            }
        };
    }
Run Code Online (Sandbox Code Playgroud)

在这个问题上: …

c# camera android android-camera xamarin

2
推荐指数
1
解决办法
3804
查看次数

标签 统计

android ×1

android-camera ×1

c# ×1

camera ×1

xamarin ×1