public async Task <Prediction> PredictAsync(Image <Rgba32> image) { var preprocessor = new Preprocessor(Rgba32.Black, Rgba32.White); image = preprocessor.Preprocess(image); var customVision = new CustomVisionPredictionClient(_httpClient, false) { ApiKey = _apiKey, Endpoint = _baseUrl, }; var stream = new MemoryStream(); image.SaveAsPng(stream); var prediction = (await customVision.ClassifyImageWithHttpMessagesAsync(_projectId, _publishedName, stream)).Body; var tag = prediction.Predictions.OrderByDescending(p => p.Probability).First(); return(new Prediction { Tag = Convert.ToInt32(tag.TagName), Probability = tag.Probability }); }