I’m trying to render a bitmap using both Gdi and Direct 2D on a compatible render target.
I create the compatible target with D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE option and then I do as follows:
HDC hdc=NULL;
ID2D1GdiInteropRenderTarget *gdiTarget=NULL;
target->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&gdiTarget);
target.BeginDraw();
HRESULT hr=gdiTarget->GetDC(D2D1_DC_INITIALIZE_MODE_CLEAR, &hdc);
if(SUCCEEDED(hr))
{
/* Gdi drawing code(hdc)*/
gdiTarget->ReleaseDC(NULL);
}
/* Direct2D drawing code
target->EndDraw();
gdiTarget->Release();
But it seems that something goes wrong, because every time I call this render method I get many GDI objects leaks. I try doing this too:
HDC hdc=NULL;
ID2D1GdiInteropRenderTarget *gdiTarget=NULL;
target->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&gdiTarget);
target.BeginDraw();
HRESULT hr=gdiTarget->GetDC(D2D1_DC_INITIALIZE_MODE_CLEAR, &hdc);
if(SUCCEEDED(hr))
gdiTarget->ReleaseDC(NULL);
target->EndDraw();
gdiTarget->Release();
and i get leaks as well.
I also try with DeleteDC() or ReleaseDC() on HDC created by ID2D1GdiInteropRenderTarget but have no success.
Any suggestion?
Thanks in advance!
I found the problem. It was a not released d2dBitmap that sometimes caused memory leaks, and, when I tried to release the ID2D1GdiInteropRenderTarget, it caused Gdi object leaks.
I’m still a little confused about which type of target is better to use (DC or Hwnd), because I found different performance depending on whether or not I used the Gpu.
In particular, I found the following problems:
Has anyone encountered the same problems?
Can you recommend something about it?