New .NET 10 sample shows how to create image descriptions using local AI

Microsoft has released a new .NET 10 sample that demonstrates how to generate alternative text for images using C# and local AI models. This new capability allows developers to create accessible and SEO-friendly applications without relying on cloud services. By combining local inference with simple code, it’s now easier than ever to enhance user experience in a privacy-first way.

Here’s what you need to know:

  • What is Alt Text?

    Alt (alternative) text helps screen readers describe images to visually impaired users. It also boosts SEO and improves overall user experience.

  • Use Local AI Models with Ollama

    Ollama supports vision-capable models like gemma:3, llama3.2-vision, and mistral-small3.2 ideal for analyzing image content and generating rich, natural-language descriptions.

  • Run C# Like a Script

    With .NET 10, you can now run C# files directly using dotnet run. This makes it easy to script tasks like image processing and automation.

  • See It in Action

    Save your code as alttext.cs, then run it with dotnet run alttext.cs followed by your image path. Ensure Ollama is running and that the image path is valid.

  • Pro Tip:

    If your image is large, resize it before encoding. It’ll reduce request size and speed up model inference.