不能在xamarin上工作视觉api [英] can't work vision api on xamarin
问题描述
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屋!