我是Xamarin的新手,因此尝试将相机流实现为xaml布局.
Xamarin的这个示例将把整个textureview设置为布局,因此我无法添加一些额外的功能,例如按钮等.
using System;
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Android.Hardware;
using static Android.App.ActionBar;
namespace TextureViewCameraStream
{
[Activity (Label = "TextureViewCameraStream", MainLauncher = true)]
public class Activity1 : Activity, TextureView.ISurfaceTextureListener
{
Camera _camera;
TextureView _textureView;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
_textureView = new TextureView(this);
_textureView.SurfaceTextureListener = this;
SetContentView(_textureView);
}
public void OnSurfaceTextureAvailable (Android.Graphics.SurfaceTexture surface, int w, int h)
{
_camera = Camera.Open ();
_textureView.LayoutParameters = new FrameLayout.LayoutParams (w, h);
try {
_camera.SetPreviewTexture (surface);
_camera.StartPreview ();
} catch (Java.IO.IOException ex) {
Console.WriteLine (ex.Message);
}
}
public bool OnSurfaceTextureDestroyed (Android.Graphics.SurfaceTexture surface)
{
_camera.StopPreview ();
_camera.Release ();
return true;
}
public void OnSurfaceTextureSizeChanged (Android.Graphics.SurfaceTexture surface, int width, int height)
{
// camera takes care of this
}
public void OnSurfaceTextureUpdated (Android.Graphics.SurfaceTexture surface)
{
}
}
}
例如,我的布局必须是:
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button1" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textureView1"
android:layout_marginTop="0.0dp" />
谁能帮助我在布局xaml的“ textureView1”中添加相机预览?
提前致谢!