Freigeben über


ContentSafetyClient.AnalyzeImageAsync Method

Definition

Overloads

AnalyzeImageAsync(RequestContent, RequestContext)

[Protocol Method] Analyze Image

AnalyzeImageAsync(BinaryData, CancellationToken)

Analyze Image with Binary Data Async.

AnalyzeImageAsync(Uri, CancellationToken)

Analyze Image with Blob URI Async.

AnalyzeImageAsync(AnalyzeImageOptions, CancellationToken)

Analyze Image.

AnalyzeImageAsync(RequestContent, RequestContext)

Source:
ContentSafetyClient.cs
Source:
ContentSafetyClient.cs

[Protocol Method] Analyze Image

public virtual System.Threading.Tasks.Task<Azure.Response> AnalyzeImageAsync (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member AnalyzeImageAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.AnalyzeImageAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function AnalyzeImageAsync (content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

content
RequestContent

The content to send as the body of the request.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The response returned from the service.

Exceptions

content is null.

Service returned a non-success status code.

Examples

This sample shows how to call AnalyzeImageAsync and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    image = new object(),
});
Response response = await client.AnalyzeImageAsync(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString());

This sample shows how to call AnalyzeImageAsync with all request content and parse the result.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    image = new
    {
        content = new object(),
        blobUrl = "http://localhost:3000",
    },
    categories = new object[]
    {
        "Hate"
    },
    outputType = "FourSeverityLevels",
});
Response response = await client.AnalyzeImageAsync(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("category").ToString());
Console.WriteLine(result.GetProperty("categoriesAnalysis")[0].GetProperty("severity").ToString());

Applies to

AnalyzeImageAsync(BinaryData, CancellationToken)

Source:
ContentSafetyClient.cs

Analyze Image with Binary Data Async.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>> AnalyzeImageAsync (BinaryData content, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeImageAsync : BinaryData * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
override this.AnalyzeImageAsync : BinaryData * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
Public Overridable Function AnalyzeImageAsync (content As BinaryData, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AnalyzeImageResult))

Parameters

content
BinaryData
cancellationToken
CancellationToken

Returns

Applies to

AnalyzeImageAsync(Uri, CancellationToken)

Source:
ContentSafetyClient.cs

Analyze Image with Blob URI Async.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>> AnalyzeImageAsync (Uri blobUri, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeImageAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
override this.AnalyzeImageAsync : Uri * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
Public Overridable Function AnalyzeImageAsync (blobUri As Uri, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AnalyzeImageResult))

Parameters

blobUri
Uri
cancellationToken
CancellationToken

Returns

Applies to

AnalyzeImageAsync(AnalyzeImageOptions, CancellationToken)

Source:
ContentSafetyClient.cs
Source:
ContentSafetyClient.cs

Analyze Image.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>> AnalyzeImageAsync (Azure.AI.ContentSafety.AnalyzeImageOptions options, System.Threading.CancellationToken cancellationToken = default);
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>> AnalyzeImageAsync (Azure.AI.ContentSafety.AnalyzeImageOptions body, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeImageAsync : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
override this.AnalyzeImageAsync : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
abstract member AnalyzeImageAsync : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
override this.AnalyzeImageAsync : Azure.AI.ContentSafety.AnalyzeImageOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeImageResult>>
Public Overridable Function AnalyzeImageAsync (options As AnalyzeImageOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AnalyzeImageResult))
Public Overridable Function AnalyzeImageAsync (body As AnalyzeImageOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AnalyzeImageResult))

Parameters

optionsbody
AnalyzeImageOptions

The image analysis request.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

options is null.

Examples

This sample shows how to call AnalyzeImageAsync.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

AnalyzeImageOptions options = new AnalyzeImageOptions(new ContentSafetyImageData());
Response<AnalyzeImageResult> response = await client.AnalyzeImageAsync(options);

This sample shows how to call AnalyzeImageAsync with all parameters.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
ContentSafetyClient client = new ContentSafetyClient(endpoint, credential);

AnalyzeImageOptions options = new AnalyzeImageOptions(new ContentSafetyImageData())
{
    Categories = { ImageCategory.Hate },
    OutputType = AnalyzeImageOutputType.FourSeverityLevels,
};
Response<AnalyzeImageResult> response = await client.AnalyzeImageAsync(options);

Remarks

A synchronous API for the analysis of potentially harmful image content. Currently, it supports four categories: Hate, SelfHarm, Sexual, and Violence.

Applies to