Jump to content
  • Advertisement
Sign in to follow this  
hop9

Direct2D alpha in bitmaps issue

This topic is 2501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm beginning to learn Direct2D, and I'm having a very basic issue getting the backgrounds of bitmaps to be clear. I have a bitmap with a clear background, but when I draw it with Direct2D the background area is drawn white. I've saved it correctly with an alpha channel and multiple image editing programs confirm that the background is clear.



I found this topic where someone seemed to have the same issue and solved it. I believe I'm setting the correct properties for my bitmap and render target. I'll post the pieces of relevant code.

Here's where I load and create the bitmap:
HRESULT hr = pIWICFactory->CreateDecoderFromFilename(
uri,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
&pDecoder
);

if (SUCCEEDED(hr))
{
// Create the initial frame.
hr = pDecoder->GetFrame(0, &pSource);
}


if (SUCCEEDED(hr))
{

hr = pIWICFactory->CreateFormatConverter(&pConverter);

}


if (SUCCEEDED(hr))
{
hr = pConverter->Initialize(
pSource,
GUID_WICPixelFormat32bppPRGBA,
WICBitmapDitherTypeNone,
NULL,
0.f,
WICBitmapPaletteTypeMedianCut
);
}

if (SUCCEEDED(hr))
{
D2D1_PIXEL_FORMAT pixelFormat = D2D1::PixelFormat(
DXGI_FORMAT_R8G8B8A8_UNORM,
D2D1_ALPHA_MODE_PREMULTIPLIED
);

D2D1_BITMAP_PROPERTIES props = D2D1::BitmapProperties();
props.pixelFormat = pixelFormat;

// Create a Direct2D bitmap from the WIC bitmap.
hr = pRenderTarget->CreateBitmapFromWicBitmap(
pConverter,
props,
ppBitmap
); }



Here's where I create the render target:
// Create a pixel format and initial its format
// and alphaMode fields.
D2D1_PIXEL_FORMAT pixelFormat = D2D1::PixelFormat(
DXGI_FORMAT_R8G8B8A8_UNORM,
D2D1_ALPHA_MODE_PREMULTIPLIED
);

D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties();
props.pixelFormat = pixelFormat;


// Create a Direct2D render target.
hr = m_pD2DFactory->CreateHwndRenderTarget(
props,
D2D1::HwndRenderTargetProperties(m_hwnd, size),
&m_pRenderTarget );



I draw the bitmap with a simple DrawBitmap call.

Does anyone see anything wrong with my code or has any clue what my issue could be?

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!