不能在xamarin上工作视觉api [英] can't work vision api on xamarin

查看:73
本文介绍了不能在xamarin上工作视觉api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ring   imagePathorUrl   =   string Empty ;

         私有 &NBSP ; IVisionServiceClient   visionClient ;





         async   void   AnalyzeImage   string   imagePathOrUrl

          {



             //                < span style ="color:#54a649"> ShowInfo
  " 分析 "
;

              AnalysisResult   < span style ="color:#dcdcdc"> analysisResult
  =   null ;
$


              string   ; resultStr   =   string ;

             try < /跨度> < span style ="color:#dcdcdc">  {

                 if   文件存在   imagePathOrUrl ))   {

        ;使用            FileStream   stream   =   文件打开   imagePathOrUrl   FileMode。打开 ))   {

  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; analysisResult   =   visionClient 分析ImageAsync   stream 结果;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;   控制台   analysisResult ;
$


         ;             }

                 }   else   if   Uri IsWellFormedUriString   imagePathOrUrl   UriKind。绝对 ))   {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <跨度style ="color:#dcdcdc"> analysisResult   =   visionClient AnalyzeImageAsync   imagePathOrUrl   null 结果;
                 ;      控制台 &NBSP; analysisResult <跨度风格="color:#dcdcdc">);
$


      ;            }   else   {

                      //                           ShowError   " 无效   图像   路径     Url " ;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; }

              }   catch   ClientException   e   {

      ;            if   e 错误  ! =   null   {

            ;          控制台   e 错误消息 ;

                      //                          this ShowError   e 错误 消息 < span style ="co lor:#54a649">)
;

   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; } <跨度style ="color:#dcdcdc">  else   {

          ;            控制台   e 错误消息 ;
$


        ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NB sp;        //   &NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;             ShowError   e < span style ="color:#54a649">。 消息 ;

                  }



                  return ; $
             }   catch   例外   {

                 //                 &n bsp;   ShowError   " 部分   错误   发生 " ;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;     return ;

              }



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; 控制台   analysisResult ;
$


//           ;       ShowAnalysisResult   analysisResult ;

         }


ring imagePathorUrl = string.Empty;
        private  IVisionServiceClient visionClient;


        async void AnalyzeImage (string imagePathOrUrl)
        {

            //            this.ShowInfo ("Analyzing");
            AnalysisResult analysisResult = null;

            string resultStr = string.Empty;
            try {
                if (File.Exists (imagePathOrUrl)) {
                    using (FileStream stream = File.Open (imagePathOrUrl, FileMode.Open)) {
                        analysisResult = this.visionClient.AnalyzeImageAsync (stream).Result;
                        Console.Write (analysisResult);

                    }
                } else if (Uri.IsWellFormedUriString (imagePathOrUrl, UriKind.Absolute)) {
                    analysisResult = visionClient.AnalyzeImageAsync (imagePathOrUrl, null).Result;
                    Console.Write (analysisResult);

                } else {
                    //                    this.ShowError ("Invalid image path or Url");
                }
            } catch (ClientException e) {
                if (e.Error != null) {
                    Console.Write (e.Error.Message);
                    //                    this.ShowError (e.Error.Message);
                } else {
                    Console.Write (e.Error.Message);

                    //                    this.ShowError (e.Message);
                }

                return;
            } catch (Exception) {
                //                this.ShowError ("Some error happened.");
                return;
            }

            Console.Write (analysisResult);

//            this.ShowAnalysisResult (analysisResult);
        }

这也是我的触发器 

     受保护   覆盖   async   void   OnCreate   Bundle   savedInstanceState

         {

              base OnCreate & nbsp; savedInstanceState ;
$


              SetContentView   资源布局主要 ;




             RootObject   ro   ; =   new   RootObject   ();

//                XRequest   ;

//                visionClient   =   new   VisionServiceClient   " c37ff7c34db145e9b73cf2630308fb07 " ;

              尝试   {

              &NBSP;&NBSP;&NBSP;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;      visionClient &NBSP; = <跨度风格=" 颜色:#dcdcdc ">&NBSP;   VisionServiceClient   " c37ff7c31fzb145e9b73cf2630308fb07 " ;

                  AnalyzeImage   " https / / scontent - ams3 - 1 xx fbcdn net / hphotos - xaf1 / v / t1 0 - 9 / 10247239_826866984028483_1194786633566871632_n jpg oh
= a865d983a6ba6f6eedbcb5715f3834dc & oe = 56D4DBB5 " ;




             }   catch &NBSP; 异常 < span style ="color:#dcdcdc">  ex   {
$


      ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;& nbsp;   }

    protected override async void OnCreate (Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);

            SetContentView (Resource.Layout.Main);


            RootObject ro = new RootObject ();
//            XRequest ();
//            this.visionClient = new VisionServiceClient ("c37ff7c34db145e9b73cf2630308fb07");
            try {
                
                visionClient = new VisionServiceClient ("c37ff7c31fzb145e9b73cf2630308fb07");
                AnalyzeImage ("https://scontent-ams3-1.xx.fbcdn.net/hphotos-xaf1/v/t1.0-9/10247239_826866984028483_1194786633566871632_n.jpg?oh=a865d983a6ba6f6eedbcb5715f3834dc&oe=56D4DBB5");

            } catch (Exception ex) {

            }

推荐答案

我现在没有答案,但发帖是为了让您知道您已发布了API密钥,因此您可能希望尽快生成新的密钥。

I don't have an answer right now but posting to let you know that you've published your API key, so you probably want to generate a new one ASAP.

我目前没有Xamarin环境。 你能告诉我这个例外是什么吗?

I don't have a Xamarin environment at the moment.  Can you tell me what the exception is?


这篇关于不能在xamarin上工作视觉api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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