如何在Xamarin表单中使用Wikitude插件? [英] How to use wikitude plugin in xamarin forms?

查看:123
本文介绍了如何在Xamarin表单中使用Wikitude插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Xamarin to develop cross platform AR application. I am using Wikitude instant tracking.

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

I am able to start the Wikitude activity and able to run the Instant tracking...Now I want capture the high resolution image while tracking...I am trying to build the plugin to get the frame and then convert it to image stream

她是我的Wikitude活动

Her is my 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);
            }

    }

我的插件代码来自

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]);
            }
        }
    }

}

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

I have registered the plugins but it is not calling
public override void Update(RecognizedTarget[] p0) Method....What am I doing wrong here ?

推荐答案

我认为问题是使用错误的方法调用"RegisterPlugin",因为您知道调用活动方法的周期不同.您应该在"OnPostCreate"中调用活动方法. 尝试下面的代码,让我知道结果:

I think the problem is calling "RegisterPlugin" in the wrong method, as you know the cycle of calling activity methods are different.you should call it in "OnPostCreate" method of activity. try below code and let me know the result:

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); }
    }

考虑更改变量名称.

这篇关于如何在Xamarin表单中使用Wikitude插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆