我正在研究MS的新API,并且在阅读教程时遇到错误。 这是我的完整代码。我试图用这个获得图像的颜色。 我得到的回报是“错误返回CV”所以我没有得到null imageStream 也不分析结果。 先感谢您!
namespace UWPApp1
{
public sealed partial class MainPage : Page
{
IRandomAccessStream imageStream;
const string APIKEY_CV = [MyComputerVisionKeyComesHere];
VisionServiceClient VisionClient = new VisionServiceClient(APIKEY_CV);
AnalysisResult analysisResult;
public MainPage()
{
this.InitializeComponent();
}
private async void button_Click(object sender, RoutedEventArgs e)
{
try
{
FileSavePicker fileSavePicker = new FileSavePicker();
fileSavePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileSavePicker.FileTypeChoices.Add("JPEG files", new List<string>() { ".jpg" });
fileSavePicker.SuggestedFileName = "image";
var outputFile = await fileSavePicker.PickSaveFileAsync();
if (outputFile == null)
{
// The user cancelled the picking operation
return;
}
imageStream = await outputFile.OpenAsync(FileAccessMode.Read);
BitmapImage imageTest = new BitmapImage();
imageTest.SetSource(imageStream);
image.Source = imageTest;
}
catch {
textBox.Text = "Error taking photo";
}
}
private async void button1_Click(object sender, RoutedEventArgs e)
{
try
{
VisualFeature[] feature = new VisualFeature[] { VisualFeature.Tags, VisualFeature.Description, VisualFeature.Color };
analysisResult = await VisionClient.AnalyzeImageAsync(imageStream.AsStream(), feature);
if (analysisResult != null)
{
var color = analysisResult.Color;
textBox.Text = "The Accent Color is" + color.AccentColor;
}
else {
textBox.Text = "analysisResult is null";
}
}
catch {
textBox.Text = "Error Return CV";
}
}
}
答案 0 :(得分:1)