如何在 xamarin 表单中使用 wikitude 插件?

How to use wikitude plugin in xamarin forms?

我正在使用 Xamarin 开发跨平台 AR 应用程序。我正在使用 Wikitude 即时跟踪。

我能够启动 Wikitude activity 并能够 运行 即时跟踪...现在我想在跟踪时捕获高分辨率图像...我正在尝试构建插件获取帧然后将其转换为图像流

她是我的 Wikitude activity

 namespace XamarinExample.Droid
    {
        [Activity(Label = "WikitudeActivity")]
        public class WikitudeActivity : Activity, ArchitectView.IArchitectUrlListener
        {
            ArchitectView architectView;
            string worldUrl;

            protected override void OnCreate(Bundle bundle)
            {
                base.OnCreate(bundle);

                SetContentView(Resource.Layout.sample_cam);

                Title = Intent.GetStringExtra("id");

                worldUrl = "Wikitude" + File.Separator + Intent.GetStringExtra("id") + File.Separator + "index.html";

                architectView = FindViewById<ArchitectView>(Resource.Id.architectView);

                ArchitectStartupConfiguration startupConfiguration = new ArchitectStartupConfiguration();
                startupConfiguration.setLicenseKey(Constants.WIKITUDE_SDK_KEY);
                startupConfiguration.setFeatures(ArchitectStartupConfiguration.Features.ImageTracking);
                startupConfiguration.setCameraResolution(CameraSettings.CameraResolution.Auto);



/////////////////////////////// Register  Plugin////////////////////////////////////


                var plugins = new Plugin01("test");
                architectView.RegisterPlugin(plugins);

                architectView.OnCreate(startupConfiguration);
                architectView.RegisterUrlListener(this);
            }

    }

My Plugin code taken from

public class Plugin01 : Com.Wikitude.Common.Plugins.Plugin
 {
    public Plugin01(string p0) : base(p0)
    {

    }    
    Frame currentFrame = null;
    public override void CameraFrameAvailable(Frame p0)
    {
    System.Diagnostics.Debug.WriteLine("AVAILABLE FRAME");
        try
        {
            var data = p0.GetData();
            currentFrame = p0;
        }
        catch (System.Exception ex) { }
    }

    public override void Update(RecognizedTarget[] p0)
    {
            System.Diagnostics.Debug.WriteLine("AVAILABLE FRAME");
        if (p0 != null)
        {
            if (currentFrame != null)
            {
               // ConvertYuvToJpeg(currentFrame, p0[0]);
            }
        }
    }

}

我已经注册了插件,但它没有调用
public 覆盖 void Update(RecognizedTarget[] p0) 方法....我在这里做错了什么?

我认为问题是在错误的方法中调用了 "RegisterPlugin",如您所知,调用 activity 方法的循环是 different.you 应该在 "OnPostCreate" 方法中调用它activity。 试试下面的代码,让我知道结果:

protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        try
        {
            SetContentView(Resource.Layout.Main);
            architectView = FindViewById<ArchitectView>(Resource.Id.architectView);
            var config = new ArchitectStartupConfiguration();
            config.setLicenseKey(WIKITUDE_SDK_KEY);
            architectView.OnCreate(config);
        }
        catch (Exception ex) { Toast.MakeText(this, ex.ToString(), ToastLength.Long); }
    }

protected override void OnPostCreate(Bundle savedInstanceState)
    {
        base.OnPostCreate(savedInstanceState);
        if (architectView != null)
            architectView.OnPostCreate();
        try
        {
            try
            {
                string url = string.Format(@"file:///android_asset/01_ImageRecognition_1_ImageOnTarget/index.html");
                architectView.Load(url);
                Plugin01 cardPlugin = new Plugin01("com.plugin.dpiar");
                architectView.RegisterPlugin(cardPlugin);
            }
            catch (Exception ex) { }
        }
        catch (Exception ex) { Toast.MakeText(this, ex.ToString(), ToastLength.Long); }
    }

考虑更改变量名称。