Android相机多个预览流,Xamarin Android从相机显示流

这篇博客讲述了作者作为Xamarin新手遇到的问题,即如何在Xaml布局中添加相机预览并保留空间放置其他元素,如按钮。示例代码展示了一个使用TextureView实现相机流的Activity,但作者希望将相机预览限制在布局的一个部分。他们寻求帮助以在名为"textureView1"的布局组件中集成相机预览功能。
摘要由CSDN通过智能技术生成

我是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”中添加相机预览?

提前致谢!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值