简体   繁体   English

捕获相机提要 .net maui

[英]Capturing camera feed .net maui

I'm new to Xamarin and Maui, I've been working on an app and now I need a way to access the camera feed.我是 Xamarin 和 Maui 的新手,我一直在开发一个应用程序,现在我需要一种访问相机源的方法。

I want to be able to preview the camera, for android first, within the app and capture an image when a buton is pressed.我希望能够首先在应用程序中预览相机,对于 android,并在按下按钮时捕获图像。 I have it working with the native camera app (media selector) but this isn't what would fulfil my requirements.我让它与本机相机应用程序(媒体选择器)一起使用,但这不能满足我的要求。

I've been trying to use handlers with Android camera X to get a preview view on the layout but I just can't crack it, there's hardly any direction on building one from the ground up.我一直在尝试使用带有 Android 相机 X 的处理程序来获得布局的预览视图,但我就是无法破解它,几乎没有任何方向可以从头开始构建一个。 Does anyone have any experience with this that might be able to point me in the right direction?有没有人有这方面的经验可以指出我正确的方向?

You can try to use .NET Multi-platform App UI (.NET MAUI) IMediaPicker interface .您可以尝试使用.NET Multi-platform App UI (.NET MAUI) IMediaPicker 界面 This interfaces lets a user pick or take a photo or video on the device。此界面允许用户在设备上选择或拍摄照片或视频。

To get photo, use code like:要获取照片,请使用如下代码:

FileResult photo = await MediaPicker.Default.CapturePhotoAsync();

我有同样的问题,我在想可能是为 Android 和 iOS 使用一些本机库,并有一个类库来捕获框架并尝试在 Maui 项目的视图中显示它

ANSWER: I ended up creating a custom handler for maui and building my own view using native android.解答:我最终为 maui 创建了一个自定义处理程序,并使用本机 android 构建了我自己的视图。 Built the view using xamarin in c#.在 c# 中使用 xamarin 构建视图。 Then used an interface to call back to the handler that an image had been taken.然后使用一个接口回调处理程序,该处理程序已拍摄图像。

I have this working in Android and iOS. I thought I should post here in case anyone might have a need for this.我在 Android 和 iOS 工作。我想我应该在这里发帖,以防有人需要这个。 There are some Catch22s that I'll mention later.我稍后会提到一些 Catch22。

In this first code block you'll see the code for the View.在第一个代码块中,您将看到视图的代码。 I've called it CameraPerson because there is a Person image overlay.我称它为 CameraPerson,因为它有一个人物图像叠加层。 This is the code that gets put in the RootFolder or a non-Platform folder.这是放在 RootFolder 或非平台文件夹中的代码。 I put mine in a folder called MultiTargeting.我将我的放在一个名为 MultiTargeting 的文件夹中。

using System.ComponentModel;
public class CameraPerson : View
{
    public CameraPerson()
    {

    }

    public enum IMAGE_TYPE
    {
        Profile,
        Wound
    }

    public enum CAMERA_TYPE
    {
        Forward,
        Back
    }

    public static readonly BindableProperty ImageTypeProperty =
        BindableProperty.Create(nameof(ImageType), typeof(IMAGE_TYPE), typeof(CameraPerson), IMAGE_TYPE.Wound);

    public static readonly BindableProperty PatientIdProperty =
        BindableProperty.Create(nameof(PatientId), typeof(int), typeof(CameraPerson), 0);

    public static readonly BindableProperty CameraTypeProperty =
        BindableProperty.Create(nameof(CameraType), typeof(CAMERA_TYPE), typeof(CameraPerson), CAMERA_TYPE.Back);

    public static readonly BindableProperty LocalIdProperty =
        BindableProperty.Create(nameof(LocalId), typeof(long), typeof(CameraPerson), null);


    public IMAGE_TYPE ImageType
    {
        get { return (IMAGE_TYPE)GetValue(ImageTypeProperty); }
        set { SetValue(ImageTypeProperty, value); }
    }

    public int PatientId
    {
        get { return (int)GetValue(PatientIdProperty); }
        set { SetValue(PatientIdProperty, value); }
    }

    public CAMERA_TYPE CameraType
    {
        get { return (CAMERA_TYPE)GetValue(CameraTypeProperty); }
        set { SetValue(CameraTypeProperty, value); }
    }

    public long LocalId
    {
        get { return (long)GetValue(LocalIdProperty); }
        set { SetValue(LocalIdProperty, value); }
    }
}

To be continued as I'm limited to character counts.待续,因为我仅限于字符数。

Any updates on this?关于这方面的任何更新? @aktikt1? @aktikt1?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM