Table of Contents

Class ImageExtensions

Namespace
Akavache
Assembly
Akavache.dll

Extension methods for working with images and bitmaps in the cache.

public static class ImageExtensions
Inheritance
ImageExtensions

Methods

IsValidImageFormat(byte[])

Validates that the provided bytes represent a valid image format by checking file headers.

public static bool IsValidImageFormat(this byte[] imageBytes)

Parameters

imageBytes byte[]

The image bytes to validate.

Returns

bool

true if the bytes appear to be a valid image format; otherwise, false.

LoadImageBytes(IBlobCache, string)

Loads image data from the blob cache as raw bytes.

public static IObservable<byte[]> LoadImageBytes(this IBlobCache blobCache, string key)

Parameters

blobCache IBlobCache

The blob cache to load the image from.

key string

The cache key to look up.

Returns

IObservable<byte[]>

An observable that emits the image bytes.

LoadImageBytesFromUrl(IBlobCache, string, bool, DateTimeOffset?)

Downloads an image from a remote URL and returns the image bytes. This method combines DownloadUrl and LoadImageBytes functionality, using cached values when possible.

public static IObservable<byte[]> LoadImageBytesFromUrl(this IBlobCache blobCache, string url, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)

Parameters

blobCache IBlobCache

The blob cache to store and retrieve the image data.

url string

The URL to download the image from.

fetchAlways bool

A value indicating whether to always fetch the image from the URL, bypassing the cache.

absoluteExpiration DateTimeOffset?

An optional expiration date for the cached image data.

Returns

IObservable<byte[]>

An observable that emits the image bytes.

LoadImageBytesFromUrl(IBlobCache, string, string, bool, DateTimeOffset?)

A combination of DownloadUrl and LoadImageBytes, this method fetches an image from a remote URL (using the cached value if possible) and returns the image bytes.

public static IObservable<byte[]> LoadImageBytesFromUrl(this IBlobCache blobCache, string key, string url, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)

Parameters

blobCache IBlobCache

The blob cache to load the image from if available.

key string

The key to store with.

url string

The URL to download.

fetchAlways bool

If we should always fetch the image from the URL even if we have one in the blob.

absoluteExpiration DateTimeOffset?

An optional expiration date.

Returns

IObservable<byte[]>

A Future result representing the image bytes.

LoadImageBytesFromUrl(IBlobCache, string, Uri, bool, DateTimeOffset?)

A combination of DownloadUrl and LoadImageBytes, this method fetches an image from a remote URL (using the cached value if possible) and returns the image bytes.

public static IObservable<byte[]> LoadImageBytesFromUrl(this IBlobCache blobCache, string key, Uri url, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)

Parameters

blobCache IBlobCache

The blob cache to load the image from if available.

key string

The key to store with.

url Uri

The URL to download.

fetchAlways bool

If we should always fetch the image from the URL even if we have one in the blob.

absoluteExpiration DateTimeOffset?

An optional expiration date.

Returns

IObservable<byte[]>

A Future result representing the image bytes.

LoadImageBytesFromUrl(IBlobCache, Uri, bool, DateTimeOffset?)

A combination of DownloadUrl and LoadImageBytes, this method fetches an image from a remote URL (using the cached value if possible) and returns the image bytes.

public static IObservable<byte[]> LoadImageBytesFromUrl(this IBlobCache blobCache, Uri url, bool fetchAlways = false, DateTimeOffset? absoluteExpiration = null)

Parameters

blobCache IBlobCache

The blob cache to load the image from if available.

url Uri

The URL to download.

fetchAlways bool

If we should always fetch the image from the URL even if we have one in the blob.

absoluteExpiration DateTimeOffset?

An optional expiration date.

Returns

IObservable<byte[]>

A Future result representing the image bytes.

ThrowOnBadImageBuffer(byte[])

Validates image buffer data and throws an exception if the buffer is invalid.

public static IObservable<byte[]> ThrowOnBadImageBuffer(this byte[] compressedImage)

Parameters

compressedImage byte[]

The compressed image buffer to validate.

Returns

IObservable<byte[]>

An observable that emits the byte array if valid, or signals an error if the buffer is corrupt.