Table of Contents

Method CreateImageFromBitmap

Namespace
PaintDotNet.Direct2D1
Assembly
PaintDotNet.Windows.Framework.dll

CreateImageFromBitmap(IDeviceContext, IBitmapSource, IDeviceColorContext?, BitmapImageOptions)

Creates an image that renders the given bitmap. This method supports bitmaps of arbitrary sizes and in many pixel formats, whereas CreateBitmap() is limited by the MaximumBitmapSize property and requires that the bitmap be in a pixel format natively supported by Direct2D (e.g. indexed or straight alpha pixel formats are not supported).

public static IBitmapImage CreateImageFromBitmap(this IDeviceContext deviceContext, IBitmapSource bitmap, IDeviceColorContext? bitmapColorContext, BitmapImageOptions options = BitmapImageOptions.Default)

Parameters

deviceContext IDeviceContext

The IDeviceContext to use for creating resources.

bitmap IBitmapSource

The IBitmapSource or IBitmap to create an IBitmapImage for.

bitmapColorContext IDeviceColorContext

The optionally specified color context information. This will be used when converting to the device context's color space. If null is specified then the default color context for the bitmap's pixel format will be used (e.g. sRGB for Bgra32, scRGB for Rgba128Float).

options BitmapImageOptions

The options for creating the image.

Returns

IBitmapImage

Remarks

The bitmap may be cached or streamed depending on various factors, including the bitmap type (IBitmap or IBitmapSource), its size, the maximum bitmap size supported by the device context, the amount of available GPU memory, and whether hardware or software rendering is being used.

NOTE: The bitmap should not be modified after the image is created in order to guarantee correct rendering results. If the bitmap is modified after the image is created, results are undefined.

The bitmap will be converted to a format that is suitable for rendering with Direct2D. For instance, if the bitmap is not in a premultiplied alpha format, it will be premultiplied unless the UseStraightAlpha option is specified. Indexed pixel formats are also supported. Alpha8 bitmaps will be converted to a mask where each pixel is colored white and using the source bitmap's alpha value.

The bitmap will be converted to the color space associated with the device context, if any. This ensures, for example, that sRGB bitmaps (which is most of them) can be drawn correctly when rendering to a device context that uses linear gamma. Note that it is not always possible to determine the color contexts to use for conversion. If that is the case, color space conversion will not be performed.

Premultiplication and conversions are either performed on the GPU, or while copying the bitmap to the GPU. The bitmap is not modified by this method.

CreateImageFromBitmap(IDeviceContext, IBitmapSource, BitmapImageOptions)

Creates an image that renders the given bitmap. This method supports bitmaps of arbitrary sizes and in many pixel formats, whereas CreateBitmap() is limited by the MaximumBitmapSize property and requires that the bitmap be in a pixel format natively supported by Direct2D (e.g. indexed or straight alpha pixel formats are not supported).

public static IBitmapImage CreateImageFromBitmap(this IDeviceContext deviceContext, IBitmapSource bitmap, BitmapImageOptions options = BitmapImageOptions.Default)

Parameters

deviceContext IDeviceContext
The IDeviceContext to use for creating resources.
bitmap IBitmapSource
The IBitmapSource or IBitmap to create an IBitmapImage for.
options BitmapImageOptions
The options for creating the image.

Returns

IBitmapImage

Remarks

The bitmap may be cached or streamed depending on various factors, including the bitmap type (IBitmap or IBitmapSource), its size, the maximum bitmap size supported by the device context, the amount of available GPU memory, and whether hardware or software rendering is being used.

NOTE: The bitmap should not be modified after the image is created in order to guarantee correct rendering results. If the bitmap is modified after the image is created, results are undefined.

The bitmap will be converted to a format that is suitable for rendering with Direct2D. For instance, if the bitmap is not in a premultiplied alpha format, it will be premultiplied unless the UseStraightAlpha option is specified. Indexed pixel formats are also supported. Alpha8 bitmaps will be converted to a mask where each pixel is colored white and using the source bitmap's alpha value.

The bitmap will be converted to the color space associated with the device context, if any. This ensures, for example, that sRGB bitmaps (which is most of them) can be drawn correctly when rendering to a device context that uses linear gamma. Note that it is not always possible to determine the color contexts to use for conversion. If that is the case, color space conversion will not be performed.

Premultiplication and conversions are either performed on the GPU, or while copying the bitmap to the GPU. The bitmap is not modified by this method.