AsyncImageLoader.Avalonia
4.0.0-preview1.2
dotnet add package AsyncImageLoader.Avalonia --version 4.0.0-preview1.2
NuGet\Install-Package AsyncImageLoader.Avalonia -Version 4.0.0-preview1.2
<PackageReference Include="AsyncImageLoader.Avalonia" Version="4.0.0-preview1.2" />
<PackageVersion Include="AsyncImageLoader.Avalonia" Version="4.0.0-preview1.2" />
<PackageReference Include="AsyncImageLoader.Avalonia" />
paket add AsyncImageLoader.Avalonia --version 4.0.0-preview1.2
#r "nuget: AsyncImageLoader.Avalonia, 4.0.0-preview1.2"
#:package AsyncImageLoader.Avalonia@4.0.0-preview1.2
#addin nuget:?package=AsyncImageLoader.Avalonia&version=4.0.0-preview1.2&prerelease
#tool nuget:?package=AsyncImageLoader.Avalonia&version=4.0.0-preview1.2&prerelease
AsyncImageLoader.Avalonia
Provides way to asynchronous bitmap loading for Avalonia Image control.
Features:
- Supports urls and downloading from web
- Asynchronous loading
- Integrated inmemory cache
- Integrated disk cache
- Easy to implement your own way of images loading and caching
Getting started
- Install
AsyncImageLoader.Avalonianuget package
dotnet add package AsyncImageLoader.Avalonia
- Start using
Using
Note: The first time you will need to import the AsyncImageLoader namespace to your xaml file. Usually your IDE should suggest it automatically. The root element in the file will be like this:
<Window ...
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
...>
Note: Assets and resources in Avalonia described here.
ImageLoader attached property
The only thing you need to do in your xaml is to replace the Source property in Image with ImageLoader.Source.
For example, your old code:
<Image Source="https://mycoolwebsite.io/image.jpg" />
Should turn into:
<Image asyncImageLoader:ImageLoader.Source="https://mycoolwebsite.io/image.jpg" />
Also you can use ImageLoader.IsLoading readonly attached property that indicates whether the load is in progress or not.
AsyncImageLoader support resm: and avares: links.
And does not support relative referenced assets such as Source="icon.png" or Source="/icon.png". Use AdvancedImage control.
AdvancedImage control
This control provides all capabilities of ImageLoader attached property and support relative referenced assets such as Source="icon.png" or Source="/icon.png".
Before you go, add following style to you App.xaml file and Application.Styles section:
<StyleInclude Source="avares://AsyncImageLoader.Avalonia/AdvancedImage.axaml" />
And you can use AdvancedImage as any other control:
<asyncImageLoader:AdvancedImage Width="150" Height="150" Source="../Assets/cat4.jpg" />
This control allows specifying a custom IAsyncImageLoader for particular control.
Also, this control has loading indicator support out of the box.
ImageBrush
If you need a brush you can use Avalonia's ImageBrush with ImageBrushLoader.Source property (instead of default Source). It will look like that:
<Border>
<Border.Background>
<ImageBrush
asyncImageLoader:ImageBrushLoader.Source="https://mycoolwebsite.io/image.jpg" />
</Border.Background>
</Border>
Image loading pipeline
ImageLoaderPipeline and ImageLoaderPipelineBuilder are the primary APIs for configuring image loading. The pipeline composes source resolution, external transport, encoded byte caching, bitmap decoding and decoded image retention. Start with the closest builder preset, then replace only the components your application needs to customize:
using AsyncImageLoader.Core;
var loader = ImageLoaderPipelineBuilder.RamCached(new MemoryImageCacheOptions {
MaxItems = 100,
AbsoluteExpiration = TimeSpan.FromMinutes(10),
SlidingExpiration = TimeSpan.FromMinutes(2)
})
.UseHttpClient(new HttpClient { Timeout = TimeSpan.FromSeconds(30) })
.UseDecoder(new MyBitmapDecoder())
.Build();
ImageLoader.AsyncImageLoader = loader;
The available presets are:
Uncached()downloads and decodes each request without retaining the decoded image.RamCached(...)shares decoded images and retains them in the lease-aware RAM cache.DiskCached(...)adds a persistent encoded disk cache for HTTP and HTTPS sources.
All presets use the same default source resolvers, HTTP transport and bitmap decoder. They are starting configurations, not separate extension hierarchies.
Set the resulting pipeline globally through ImageLoader.AsyncImageLoader or ImageBrushLoader.AsyncImageLoader, or assign it to the Loader property of an individual AdvancedImage. Dispose the previous global loader when replacing it.
Pipeline components
ImageLoadRequestcarries the source string and optional Avalonia context (BaseUriandIStorageProvider) through the pipeline.IImageSourceResolverhandles non-network sources. The defaultCompositeImageSourceResolvertriesFileImageSourceResolver,StorageImageSourceResolverandAvaloniaAssetSourceResolverin order.IImageTransportretrieves external encoded data. The defaultHttpImageTransporthandles absolute HTTP and HTTPS sources usingHttpClient.IImageByteCachestores encoded image data before decoding.DiskImageByteCachepersists HTTP responses under hashed keys and is enabled by theDiskCached(...)preset.IBitmapDecoderconverts an encoded stream into an AvaloniaBitmap. The defaultBitmapDecoderreads non-seekable streams asynchronously before constructing the bitmap.IImageMemoryCachecoordinates concurrent requests and returns independent consumer leases.TransientImageCacheperforms no retention;MemoryImageCacheprovides RAM retention with absolute and sliding expiration.IImageLeaserepresents one consumer's ownership of an image. UI integrations release their lease when a source is replaced or detached, while the memory cache controls how long its own reference is retained.ImageLoaderPipelineorchestrates these components and implementsIAsyncImageLoader.
The builder methods replace individual components:
UseSourceResolver(...)UseTransport(...)UseDecoder(...)UseMemoryCache(...)UseByteCache(...)UseHttpClient(...)
The built pipeline owns and disposes its configured memory cache. A supplied HttpClient remains caller-owned unless UseHttpClient(client, disposeHttpClient: true) is used. A builder can build only one pipeline because ownership of its cache is transferred during Build().
Compatibility loaders
The original ready-made loaders remain available as compatibility and convenience facades:
- BaseWebImageLoader corresponds to the
Uncached()preset. - RamCachedWebImageLoader corresponds to the
RamCached(...)preset and remains the default global loader. - DiskCachedWebImageLoader corresponds to the
DiskCached(...)preset.
These types delegate to the same pipeline presets. They are useful for existing applications and simple configurations, but new customization should use ImageLoaderPipelineBuilder instead of inheriting from a loader. On mobile, WASM and other restricted platforms, provide a valid writable cache path before using disk caching.
Custom loaders
You can implement every component of the pipeline individually.
Or implement IAsyncImageLoader directly only when the complete built-in pipeline is not appropriate. LoadAsync receives an ImageLoadRequest and returns an IImageLease; such an implementation replaces source resolution, transport, decoding and caching rather than customizing one pipeline stage.
Use ImageLease.Owned, ImageLease.NonOwning or ImageLease.Create to make ownership explicit when implementing a custom loader.
RAM retention
RAM retention can be configured when creating a loader. Expiration releases the loader's strong reference; if the UI still uses the bitmap, it can be reused through a weak reference:
ImageLoader.AsyncImageLoader = ImageLoaderPipelineBuilder.RamCached(new MemoryImageCacheOptions {
AbsoluteExpiration = TimeSpan.FromMinutes(10),
SlidingExpiration = TimeSpan.FromMinutes(2)
}).Build();
When both values are specified, the first expiration is used. Expiration never disposes bitmaps that have already been returned to controls.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Avalonia (>= 12.0.0)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on AsyncImageLoader.Avalonia:
| Package | Downloads |
|---|---|
|
ClassIsland.Core
ClassIsland 应用核心依赖库,包括 ClassIsland 封装的一些常用控件和方法。 |
|
|
Huskui.Avalonia.Markdown
Markdown rendering extension for Huskui.Avalonia, converting Markdown text to native Avalonia controls using Markdig. |
|
|
SuppaWallet.Gui
Package Description |
|
|
Pwa.Stories
is similar like Instagram Stories |
|
|
SuppaWallet.Gui.Desktop
Package Description |
GitHub repositories (28)
Showing the top 20 popular GitHub repositories that depend on AsyncImageLoader.Avalonia:
| Repository | Stars |
|---|---|
|
Tyrrrz/YoutubeDownloader
Downloads videos and playlists from YouTube
|
|
|
Tyrrrz/DiscordChatExporter
Saves Discord chat logs to a file
|
|
|
LykosAI/StabilityMatrix
Multi-Platform Package Manager for Stable Diffusion
|
|
|
PixiEditor/PixiEditor
PixiEditor is a Universal Editor for all your 2D needs
|
|
|
Jeric-X/SyncClipboard
跨平台剪贴板同步、历史记录管理工具 / Cross-platform cipboard syncing, history management tool
|
|
|
Tyrrrz/YoutubeExplode
Abstraction layer over YouTube's internal API
|
|
|
ClassIsland/ClassIsland
一款功能强、可定制、跨平台,适用于班级多媒体屏幕的课表信息显示工具,可以一目了然地显示各种信息。
|
|
|
SirDiabo/GithubLauncher
A Launcher that Downloads and Updates Applications from Github Releases
|
|
|
Decimation/SmartImage
Reverse image search tool (SauceNao, IQDB, Ascii2D, trace.moe, and more)
|
|
|
b-editor/beutl
Cross-platform video editing (compositing) software.
|
|
|
Artemis-RGB/Artemis
Provides advanced unified lighting across many different brands RGB peripherals
|
|
|
SnapXL/SnapX
SnapX is a free, open-source, cross-platform tool that lets you capture or record any area of your screen and instantly share it with a single keypress. Upload images, videos, text, and more to multiple supported destinations—all with ease. ShareX fork
|
|
|
rocksdanister/weather
Windows native weather app powered by DirectX12 animations
|
|
|
ETS2LA/ETS2LA
Plugin based interface program for ETS2/ATS.
|
|
|
Linsxyx/KugouMusic.NET
基于 .NET 10 与 Avalonia 打造的轻量级跨平台酷狗音乐客户端。
|
|
|
dorisoy/Dorisoy.Pan
Dorisoy.Pan 是基于 .NET 10 的跨平台文档管理系统,使用 MS SQL 2012 / MySQL 8.0(或更高版本)后端数据库,您可以在 Windows、Linux 或 Mac 上运行它。项目中的所有方法都是异步的,支持 JWT 令牌身份验证,项目体系结构遵循 CQRS + MediatR 模式和最佳安全实践。源代码完全可定制,热插拔且清晰的体系结构,使开发定制功能和遵循任何业务需求变得容易。
|
|
|
HeyM1ke/Assist
C# Valorant Thirdparty Launcher
|
|
|
h4lfheart/FortnitePorting
The quickest and most efficient way to extract assets from Fortnite
|
|
|
EllyVR/VRCVideoCacher
|
|
|
Round-Studio/BedrockBoot
一个为 Windows 和 Linux 开发的基岩版启动器
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0-preview1.2 | 31 | 8/22/2026 |
| 4.0.0-preview1.1 | 39 | 8/21/2026 |
| 4.0.0-preview1 | 93 | 8/16/2026 |
| 3.9.1-nightly.3 | 61 | 8/16/2026 |
| 3.9.1-nightly.2 | 60 | 8/15/2026 |
| 3.9.1-nightly.0.1 | 59 | 8/10/2026 |
| 3.8.0 | 25,273 | 4/19/2026 |
| 3.7.0 | 28,291 | 3/2/2026 |
| 3.6.0 | 19,749 | 2/1/2026 |
| 3.5.0 | 10,558 | 12/27/2025 |
| 3.4.4 | 1,223 | 12/21/2025 |
| 3.4.3 | 25,963 | 9/14/2025 |
| 3.4.2 | 1,586 | 9/13/2025 |
| 3.4.1 | 473 | 9/13/2025 |
| 3.4.0 | 860 | 9/10/2025 |
| 3.3.0 | 122,714 | 8/17/2024 |
| 3.2.1 | 43,860 | 9/26/2023 |
This version based on commit https://github.com/AvaloniaUtils/AsyncImageLoader.Avalonia/commit/569eb3b3b2a2ad829ce90299b6612aeaaab09a54
Merge pull request #52 from AvaloniaUtils/maxItems
Add MaxItems to the memorycache