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

  • Home
  • SEARCH
  • 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 752933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:50:19+00:00 2026-05-14T14:50:19+00:00

I have some working code that uses IImgCtx to load images, but I can’t

  • 0

I have some working code that uses IImgCtx to load images, but I can’t work out how to get at the alpha channel. For images like .gif’s and .png’s there are transparent pixels, but using anything other than a 24-bit bitmap as a drawing surface doesn’t work.

For reference on the interface:
http://www.codeproject.com/KB/graphics/JianImgCtxDecoder.aspx

My code looks like this:

IImgCtx *Ctx = 0;
HRESULT hr = CoCreateInstance(CLSID_IImgCtx, NULL, CLSCTX_INPROC_SERVER, IID_IImgCtx, (LPVOID*)&Ctx);
if (SUCCEEDED(hr))
{
    GVariant Fn = Name;
    hr = Ctx->Load(Fn.WStr(), 0);
    if (SUCCEEDED(hr))
    {
        SIZE  Size = { -1, -1 };
        ULONG State = 0;

        while (true)
        {
            hr = Ctx->GetStateInfo(&State, &Size, false);
            if (SUCCEEDED(hr))
            {
                if ((State & IMGLOAD_COMPLETE) || (State & IMGLOAD_STOPPED) || (State & IMGLOAD_ERROR))
                {
                    break;
                }
                else
                {
                    Sleep(1);
                }
            }
            else break;
        }

        if (Size.cx > 0 &&
            Size.cy > 0 &&
            pDC.Reset(new GMemDC))
        {
            if (pDC->Create(Size.cx, Size.cy, 32))
            {
                HDC hDC = pDC->StartDC();
                if (hDC)
                {
                    RECT rc = { 0, 0, pDC->X(), pDC->Y() };
                    Ctx->Draw(hDC, &rc);
                    pDC->EndDC();
                }
            }
            else pDC.Reset();
        }
    }

    Ctx->Release();

Where “StartDC” basically wraps CreateCompatibleDC(NULL) and “EndDC” wraps DeleteDC, with appropriate SelectObjects for the HBITMAPS etc. And pDC->Create(x, y, bit_depth) calls CreateDIBSection(…DIB_RGB_COLORS…). So it works if I create a 24 bits/pixel bitmap but has no alpha to speak of, and if I pass a 32 bits/pixel bitmap it fills out the RGB colour channels and leaves the alpha channel 0x00. If I OR the alpha channel with 0xff to set the image to fully opaque then it looks the same as the 24 bpp option. Now this interface apparently is used by Internet Explorer to load images, and obviously THAT supports transparency, so I believe that it’s possible to get some level of alpha out of the interface. The question is how?

(I also have fall back code that will call libpng/libjpeg/my .gif loader etc)

  • 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-05-14T14:50:20+00:00Added an answer on May 14, 2026 at 2:50 pm

    GDI does not support alpha channels. When Draw method is called for PNGs and GIFs some internal alpha blending method make its work, it does not touch alpha channel of bitmap selected in DC, it only combines color channels using internally stored alpha channel data of the PNG\GIF image.

    For 32-bit BMPs situation is quite different, there is no alpha blending, all bits are just copied into DC. If bit depth of bitmap selected in DC and bit depth of bitmap to be drawn on DC are matched then drawing on DC is just like a memcpy call. That is why sometimes there is an illusion that GDI supports alpha channels, but in fact that is just a dumb copying of bytes and copied alpha channel do not make any difference in resulting image.

    In other words, do not use GDI or any library based on it for work with alpha channels. Use GDI+, about 10 years elapsed since its release and it may be found almost on all Windows computers.

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

Sidebar

Related Questions

I have been working on some legacy C++ code that uses variable length structures
I have some really complicated legacy code I've been working on that crashes when
We are working with some new Cutting Tools that can have it's hardware parameters
I'm working on some code that uses a lot of after_save callbacks, and I
I have started working on some code left behind by previous developers, and I'm
I am working on a rails application (I have some experience with rails). But,
I've been reading up on .NET Threading and was working on some code that
I have a working test of a hardware device that uses RSA encryption, in
I am working on a small AIR desktop application and I have some configuration
On a recent project I have been working on in C#/ASP.NET I have some

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.