Why ID2D1RenderTarget::CreateBitmap returns WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT?

0

I am using ID2D1RenderTarget::CreateBitmap from D2D1.h to create ID2D1Bitmap from array of pixels but this function returns 0x88982f80 (WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT) and ID2D1Bitmap* is NULL

There is a code to create a bitmap:

hr = m_pRenderTarget->CreateBitmap(
    D2D1::SizeU(10, 10), src, 4 * 10,
    D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_R8G8B8A8_UNORM, D2D1_ALPHA_MODE_STRAIGHT)),
    &bitmap
);

if (hr < 0) exit(1); // IF FAILED EXIT WITH CODE 1

How to fix that?

Update

The solution is simple:

hr = m_pRenderTarget->CreateBitmap(
    D2D1::SizeU(10, 10), src, 4 * 10,
    D2D1::BitmapProperties(D2D1::PixelFormat(
        DXGI_FORMAT_R8G8B8A8_UNORM,
        D2D1_ALPHA_MODE_PREMULTIPLIED)
    ),
    &bitmap
);

Supported alpha modes for DXGI_FORMAT_R8G8B8A8_UNORM are:

  • D2D1_ALPHA_MODE_PREMULTIPLIED
  • D2D1_ALPHA_MODE_IGNORED
  • D2D1_ALPHA_MODE_UNKNOWN

You can also change the rendering parameters of ID2D1RenderTarget (D2D1_RENDER_TARGET_PROPERTIES) to achieve the result.

The full list of supported alpha modes for each DXGI_FORMAT you can see here: Supported Pixel Formats and Alpha Modes .

c++
graphics
2d
directx
direct2d
asked on Stack Overflow Jul 24, 2020 by Yoshi • edited Jul 26, 2020 by Yoshi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0