user21790117
user21790117

Reputation:

Direct2D different image loadings APIs

I am currently learning Direct2D and I successfully implemented image loading into my test application as described in:

How to Load a Bitmap from a File (https://learn.microsoft.com/en-us/windows/win32/direct2d/how-to-load-a-direct2d-bitmap-from-a-file) and How to Load a Bitmap from a Resource (https://learn.microsoft.com/en-us/windows/win32/direct2d/how-to-load-a-bitmap-from-a-resource)

But now I stumbled across the subsection in What's new in Direct2D -> Improved image loading APIs (https://learn.microsoft.com/en-us/windows/win32/direct2d/what-s-new-in-direct2d-for-windows-8-consumer-preview#improved-image-loading-apis).

Can someone explain to me why these new APIs for loading images are better than the ones used in "How to Load a Bitmap from a File/Resource"? As far as I understand these new functions provide D2D1Image types, which must be converted to D2D1Bitmap before they can be used by the RenderTarget?

Upvotes: 0

Views: 299

Answers (1)

Jeaninez - MSFT
Jeaninez - MSFT

Reputation: 4017

According to the Doc:Supported Pixel Formats and Alpha Modes

When you use the CreateBitmapFromWicBitmap method, you use the pixelFormat field of a D2D1_BITMAP_PROPERTIES structure (instead of the pixelFormat member of a D2D1_RENDER_TARGET_PROPERTIES structure) to specify the pixel format of the new render target. It must match the pixel format of the WIC bitmap source.

An ID2D1ImageSource is an abstracted provider of pixels. It can be instantiated from either WIC (CreateImageSourceFromWic or an IDXGISurface (CreateImageSourceFromDxgi).

CreateBitmapFromWicBitmap must match the pixel format of the WIC bitmap source. ID2D1ImageSource can be instantiated from either WIC or an IDXGISurface. An ID2D1ImageSource that is instantiated from IDXGISurface also supports some YUV pixel formats.

When you create a render target, you must specify its pixel format. For a list of pixel formats and alpha modes supported by each render target, see Supported Pixel Formats and Alpha Modes.

When you use the ID2D1RenderTarget::CreateSharedBitmap method, you use the pixelFormat field of a D2D1_BITMAP_PROPERTIES structure to specify the pixel format of the new render target. It must match the pixel format of the ID2D1Bitmap source.

Upvotes: -1

Related Questions