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
serviceIFileTypesService1The service to use for finding and creating IFileType instances.The path of the file to load from.
filePathstringThe 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
serviceIFileTypesService1The 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
nullthen the default color context fortargetPixelFormatwill be used (usually sRGB).filePathstringThe 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
nullthen the default color context fortargetPixelFormatwill be used (usually sRGB).targetPixelFormatPixelFormatThe 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
nullthen the default color context fortargetPixelFormatwill be used (usually sRGB).targetColorContextIColorContextThe 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
nullthen the default color context fortargetPixelFormatwill 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
serviceIFileTypesService1The service to use for finding and creating IFileType instances.The path of the file to load from.The target color context. If
nullthen the default color context forTPixelwill be used (usually sRGB).filePathstringThe service to use for finding and creating IFileType instances.The path of the file to load from.The target color context. If
nullthen the default color context forTPixelwill be used (usually sRGB).targetColorContextIColorContextThe service to use for finding and creating IFileType instances.The path of the file to load from.The target color context. If
nullthen the default color context forTPixelwill be used (usually sRGB).
Returns
- IFileTypeBitmapSource<TPixel>
The bitmap source. Use the
ToBitmap()extension method to convert to an IBitmap.
Type Parameters
TPixelThe color struct for the pixel format to use, e.g. ColorBgra32.