Table of Contents

Method TryLoadFileAsBitmap

Namespace
PaintDotNet.FileTypes
Assembly
PaintDotNet.FileTypes.dll

TryLoadFileAsBitmap(IFileTypesService1, string)

Like LoadFileAsBitmap(IFileTypesService1, string), but returns null instead of throwing an exception when an error is encountered.

public static IFileTypeBitmapSource? TryLoadFileAsBitmap(this IFileTypesService1 service, string filePath)

Parameters

service IFileTypesService1

The service to use for finding and creating IFileType instances.The path of the file to load from.

filePath string

The service to use for finding and creating IFileType instances.The path of the file to load from.

Returns

IFileTypeBitmapSource

The bitmap source. Use the Lock() to access the pixel data directly, or the ToBitmap() extension method to convert it to an IBitmap.

Remarks

This method will only return bitmaps in a BGRA or RGBA pixel format at 32-, 64-, or 128-bits per pixel.

TryLoadFileAsBitmap(IFileTypesService1, string, in PixelFormat, IColorContext?)

Like LoadFileAsBitmap(IFileTypesService1, string, in PixelFormat, IColorContext?), but returns null instead of throwing an exception when an error is encountered.

public static IFileTypeBitmapSource? TryLoadFileAsBitmap(this IFileTypesService1 service, string filePath, in PixelFormat targetPixelFormat, IColorContext? targetColorContext = null)

Parameters

service IFileTypesService1

The service to use for finding and creating IFileType instances.The path of the file to load from.The target pixel format.The target color context. If null then the default color context for targetPixelFormat will be used (usually sRGB).

filePath string

The service to use for finding and creating IFileType instances.The path of the file to load from.The target pixel format.The target color context. If null then the default color context for targetPixelFormat will be used (usually sRGB).

targetPixelFormat PixelFormat

The service to use for finding and creating IFileType instances.The path of the file to load from.The target pixel format.The target color context. If null then the default color context for targetPixelFormat will be used (usually sRGB).

targetColorContext IColorContext

The service to use for finding and creating IFileType instances.The path of the file to load from.The target pixel format.The target color context. If null then the default color context for targetPixelFormat will be used (usually sRGB).

Returns

IFileTypeBitmapSource

The bitmap source. Use the Lock() to access the pixel data directly, or the ToBitmap() extension method to convert it to an IBitmap.

TryLoadFileAsBitmap<TPixel>(IFileTypesService1, string, IColorContext?)

Like LoadFileAsBitmap<TPixel>(IFileTypesService1, string, IColorContext?), but returns null instead of throwing an exception when an error is encountered.

public static IFileTypeBitmapSource<TPixel>? TryLoadFileAsBitmap<TPixel>(this IFileTypesService1 service, string filePath, IColorContext? targetColorContext = null) where TPixel : unmanaged, INaturalPixelInfo

Parameters

service IFileTypesService1

The service to use for finding and creating IFileType instances.The path of the file to load from.The target color context. If null then the default color context for TPixel will be used (usually sRGB).

filePath string

The service to use for finding and creating IFileType instances.The path of the file to load from.The target color context. If null then the default color context for TPixel will be used (usually sRGB).

targetColorContext IColorContext

The service to use for finding and creating IFileType instances.The path of the file to load from.The target color context. If null then the default color context for TPixel will be used (usually sRGB).

Returns

IFileTypeBitmapSource<TPixel>

The bitmap source. Use the ToBitmap() extension method to convert to an IBitmap.

Type Parameters

TPixel

The color struct for the pixel format to use, e.g. ColorBgra32.