How can I do to instead send a parse to the local it parse an image from a remote address or a url. For if I try to replace the address: C: \ Users \ madureira \ Downloads \ JRMJ.jpg by a URL the error message appears: 'The given path format is not supported.'
Code:
protected void Button1_Click(object sender, EventArgs e)
{
string imageFilePath = @"C:\Users\madureira\Downloads\JRMJ.jpg";
Literal1.Text= ObterEmocoes(imageFilePath);
}
public async Task<string> ObterEmocoes(string imageFilePath)
{
HttpResponseMessage respostaHttp;
string json;
byte[] byteData = GetImageAsByteArray(imageFilePath);
string url = "https://brazilsouth.api.cognitive.microsoft.com/face/v1.0/detect";
string queryString = "returnFaceId=true&returnFaceLandmarks=false" +
"&returnFaceAttributes=age,gender,headPose,smile,facialHair,glasses," +
"emotion,hair,makeup,occlusion,accessories,blur,exposure,noise";
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "<<key>>");
using (ByteArrayContent content = new ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
respostaHttp = await httpClient.PostAsync($"{url}?{queryString}", content);
json = await respostaHttp.Content.ReadAsStringAsync();
}
return json;
}
static byte[] GetImageAsByteArray(string imageFilePath)
{
using (FileStream fileStream =
new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))
{
BinaryReader binaryReader = new BinaryReader(fileStream);
return binaryReader.ReadBytes((int)fileStream.Length);
}
}