1

I am trying to load an image as a tile on a Windows 10 Credential Provider that was originally written to work on Windows 7. But now the images on Windows 10 are a circle instead of a square and would like to have the rounded edges transparent. I have used a BMP image but that did not work, so I have tried loading a PNG file that is transparent on the edges but this also does not work.

I have used the following code to load a PNG file and the file loads but it only shows it as either black or white background but not transparent (the resourceId is a resource of an image that is PNG).

HBITMAP LoadPNG(HINSTANCE hInst, int resourceId)
{
    HGLOBAL     hGlobal;
    LPSTREAM    pStream;
    HBITMAP tBmp = NULL;
    ULONG_PTR token = 0;
    Gdiplus::GdiplusStartupInput input = NULL;
    Gdiplus::GdiplusStartup(&token, &input, NULL);
    if (token != 0)
    {
        HRSRC   hRsrc = FindResource(hInst, MAKEINTRESOURCE(resourceId), TEXT("PNG"));
        HGLOBAL hGlob1 = LoadResource(hInst, hRsrc);

        int size = SizeofResource(hInst, hRsrc);

        hGlobal = GlobalAlloc(GMEM_FIXED, size);
        LPVOID  resPtr = LockResource(hGlob1);
        memcpy(hGlobal, resPtr, size);
        FreeResource(hGlob1);
        CreateStreamOnHGlobal(hGlobal, true, &pStream);
        Gdiplus::Bitmap* bmp = new Gdiplus::Bitmap(pStream, false);

        bmp->GetHBITMAP(Gdiplus::Color::Transparent, &tBmp);

        Gdiplus::GdiplusShutdown(token);
    }
    return tBmp;
}

Originally I was using this to load a BMP file but BMP does not really support transparency (in this case the IDB_TILE_IMAGE is a BMP file) :

HRESULT GetBitmapValue(DWORD dwFieldID, HBITMAP* phbmp)
{
    HRESULT hr;
    if ((SFI_TILEIMAGE == dwFieldID) && phbmp)
    {
        HBITMAP hbmp = LoadBitmap(HINST_THISDLL, MAKEINTRESOURCE(IDB_TILE_IMAGE));
        if (hbmp != NULL)
        {
            hr = S_OK;
            *phbmp = hbmp;
        }
        else
        {
            hr = HRESULT_FROM_WIN32(GetLastError());
        }
    }
    else
    {
        hr = E_INVALIDARG;
    }
    
    return hr;
}

Any ideas on how to make a transparent tile image on Windows 10 Credential Provider so I can show an image with rounded transparent edges? What I am looking for is not a square image to be loaded as a tile but an actual circular image to match the Microsoft images that are out of the box from Windows 10.

Jose
  • 11
  • 2
  • What exactly do you mean by "it doesn't work"? What *did* happen when you used a square image? – Dai Jun 27 '22 at 15:11
  • "but BMP does not really support transparency" - **it does** - make sure you're handling 32-bit (RGBA) GDI bitmap objects. – Dai Jun 27 '22 at 15:14
  • Thanks for replying, what I am looking for is a circular image to be loaded. I have a PNG file that has the edges be transparent but when it is loaded by code, the image is just a square image with either white or black background instead of the edges being transparent. – Jose Jun 27 '22 at 15:17
  • I thought Windows 10+ will convert a square image to a rectangle for you automatically? Anyway, as far as I know, Windows has never supported transparency of any kind in source images (i.e. application or user supplied images via Win32 or via Control Panel / Settings)... – Dai Jun 27 '22 at 15:36
  • So are you saying this is not possible? Someone had asked a similar question in the past but not sure if they were able to get it to work. https://stackoverflow.com/questions/36989628/windows-10-credentialprovider-tile-image-transparency – Jose Jun 27 '22 at 16:29

0 Answers0