🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

The bitmap pixel format is unsupported.

Started by
1 comment, last by Key_C0de 2 years, 9 months ago

Hello.

I'm stuck with this issue that I can't seem to be able to get past.

I'm trying to load an image using WIC and pass it to Direct2D.

	// create wic format converter
	hres = m_pWicFactory->CreateFormatConverter( &m_pWicConverter );

	// setup the converter to create 32bpp BGRA bitmaps
	hres = m_pWicConverter->Initialize( m_pBitmapFrame.Get(),
		GUID_WICPixelFormat32bppBGRA,	// Pixel Format
		WICBitmapDitherTypeNone,
		nullptr,
		0.0,
		WICBitmapPaletteTypeCustom );


	// create the D2D1 bitmap
	hres = gph->getRenderTarget()->CreateBitmapFromWicBitmap( m_pWicConverter.Get(),
		nullptr,
		&m_pBitmap ); // failure here "The bitmap pixel format is unsupported."

Meanwhile my ID2D1HwndRenderTarget is created like so:

	hres = m_pFactory->CreateHwndRenderTarget( D2D1::RenderTargetProperties( D2D1_RENDER_TARGET_TYPE_HARDWARE,
			D2D1::PixelFormat( DXGI_FORMAT_B8G8R8A8_UNORM ) ),
		D2D1::HwndRenderTargetProperties( hWnd,
			size ),
		&m_pRenderTarget );

As you can see both are BGRA 8 bit per channel - the recommended format.

What am I doing wrong?

I'm on MSVS 2017.

None

Advertisement

Guys, I found the problem (stuck for hours here - smh..).

  1. 32bpp formats cannot handle Direct Alpha - They have to be set with Premultiplied alpha - so set D2D1_ALPHA_MODE_PREMULTIPLIED in D2D1::PixelFormat (default is D2D1_ALPHA_MODE_UNKNOWN).
  2. Premultiplied alpha formats require GUID_WICPixelFormat32bppPBGRA and not GUID_WICPixelFormat32bppBGRA . P for pre-multiplied.

None

This topic is closed to new replies.

Advertisement