Skip to content

Commit e52d155

Browse files
authored
Updated sample
1 parent 6a4db98 commit e52d155

File tree

2 files changed

+42
-147
lines changed

2 files changed

+42
-147
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
using System.Text;
4+
using System.Net;
5+
6+
/* This sample makes a call to the Bing Image Search API with a query image and returns visually similar images.
7+
* Details about each similar image, also known as "insights", are returned in the JSON response.
8+
* Documentation: https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/
9+
*/
10+
11+
namespace BingImageSearchInsights
12+
{
13+
class Program
14+
{
15+
// Add your Azure Bing Search v7 subscription key to your environment variables
16+
static string subscriptionKey = Environment.GetEnvironmentVariable("BING_SEARCH_V7_SUBSCRIPTION_KEY");
17+
// Add your Azure Bing Search v7 endpoint to your environment variables
18+
static string endpoint = Environment.GetEnvironmentVariable("BING_SEARCH_V7_ENDPOINT") + "/bing/v7.0/images/details";
19+
20+
// Place an image (for example a jpg or png) in your bin\Debug\netcoreapp3.0 folder.
21+
const string imageFile = "YOUR-IMAGE.jpg";
22+
23+
static void Main()
24+
{
25+
Console.OutputEncoding = Encoding.UTF8;
26+
27+
WebClient client = new WebClient();
28+
client.Headers["Ocp-Apim-Subscription-Key"] = subscriptionKey;
29+
client.Headers["ContentType"] = "multipart/form-data";
30+
// Returns all insights
31+
byte[] response = client.UploadFile(endpoint + "?modules=All", imageFile);
32+
var json = Encoding.Default.GetString(response);
33+
34+
// Pretty print the result
35+
dynamic parsedJson = JsonConvert.DeserializeObject(json);
36+
Console.WriteLine("\nBing Image Insights JSON Response:\n");
37+
Console.WriteLine(JsonConvert.SerializeObject(parsedJson, Formatting.Indented));
38+
39+
Console.ReadLine();
40+
}
41+
}
42+
}

dotnet/Search/BingImageSearchInsightsTutorial.cs

Lines changed: 0 additions & 147 deletions
This file was deleted.

0 commit comments

Comments
 (0)