Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8777783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:21:38+00:00 2026-06-13T19:21:38+00:00

I’m trying to render a bitmap using both Gdi and Direct 2D on a

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:21:40+00:00Added an answer on June 13, 2026 at 7:21 pm

    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.

    HDC hdc=NULL;
    ID2D1GdiInteropRenderTarget *gdiTarget=NULL;
    compatibleTarget->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget),(void**)&gdiTarget);
    compatibleTarget.BeginDraw();
    HRESULT hr=gdiTarget->GetDC(D2D1_DC_INITIALIZE_MODE_CLEAR, &hdc);
    if(SUCCEEDED(hr))
    {
        /* Gdi drawing code(hdc)*/
    
    gdiTarget->ReleaseDC(NULL);
    }
    /* Direct2D drawing code
    compatibleTarget->EndDraw();
    gdiTarget->Release();
    ID2D1Bitmap *bitmap=NULL;
    compatibleTarget->GetBitmap(&bitmap);
    target->BeginDraw();
    target->DrawBitmap(bitmap);
    target->EndDraw();
    compatibleTarget->Release();    // I thought this only enough
    bitmap->Release();              // This solved the problem
    

    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:

    • If I use the DCRenderTarget I can not use hardware acceleration (or Default), because I have continued violations of protected areas of memory. This does not happen if I use HwndRenderTarget.
    • If I use HwndRenderTarget, in general everything is fine, but I lose the focus on the window, which does not recognize the KeyPressed message, and, if I use the Gpu, performance fall a lot and strongly depend on the number of active targets (which does not happen if I use the software acceleration).

    Has anyone encountered the same problems?
    Can you recommend something about it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.