public static async Task <AnalyzeImageResponse> AnalyzeImage(string imagePath) { client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey); string requestParameters = "visualFeatures=Categories,Tags,Description,Faces,ImageType,Color,Adult"; string uri = uriBase + "&" + requestParameters; HttpResponseMessage response; byte[] byteData = GetImageAsByteArray(imagePath); using (ByteArrayContent content = new ByteArrayContent(byteData)) { // This example uses content type "application/octet-stream". // The other content types you can use are "application/json" // and "multipart/form-data". content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); // Make the REST API call. response = await client.PostAsync(uri, content); } // Get the JSON response. var result = await response.Content.ReadAsStringAsync(); AnalyzeImageResponse imageResponse = null; if (response.IsSuccessStatusCode) { imageResponse = AnalyzeImageResponse.FromJson(result); } return(imageResponse); }
public static string ToJson(this AnalyzeImageResponse self) => JsonConvert.SerializeObject(self, ApiLibrary.Converter.Settings);