Windows 10 CredentialProvider 平铺图像透明度
Windows 10 CredentialProvider Tile Image transparency
不久前,我为 Windows 7 创建了一个 CredentialProvider,它为用户显示了自定义磁贴图像。当我在 Windows 10 上测试我的 CredentialProvider 时,我注意到磁贴图像不像通常的 Windows 用户图像那样是圆形的,所以我假设,我必须提供我自己的具有透明度的圆形图像。我尝试加载一个透明的圆形 PNG 并在 ICredentialProviderCredentiall::GetBitmapValue()
函数中传递相应的 HBITMAP
。不幸的是,PNG 的背景不是透明的,而是白色的。有什么办法可以显示实际的透明度吗?由于HBITMAP
是LogonUI自己绘制的,我无法修改绘制行为。
为了从我的 PNG 资源中创建 HBITMAP
,我使用了以下函数:
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;
}
我还尝试了 GetHBITMAP()
背景颜色参数的其他值,例如 AlphaMask
和 AlphaShift
,但这些都不起作用(相反,白色背景变成黑色)
有什么方法可以实现我的目标吗?
最新的 Credential Provider Technical Reference(在 MSDN 上不容易找到)实际上说明了平铺图像的问题所在:
In Windows 10, the selected User/V1/PLAP credential provider has an
image size of 192x192. The ones on the bottom left list is of 48x48.
Note LogonUI uses circular image for user and square image for V1/PLAP
according to the new design direction. The image size of V2 Credential
Provider tile under a selected user is 48x48.
如果我正确阅读了文档,那么挑战一定是以某种方式让 LogonUI 相信它是一个用户而不是 V1/PLAP,我认为这可以通过在 GetSerialization 调用中返回一个虚拟用户来实现。
不久前,我为 Windows 7 创建了一个 CredentialProvider,它为用户显示了自定义磁贴图像。当我在 Windows 10 上测试我的 CredentialProvider 时,我注意到磁贴图像不像通常的 Windows 用户图像那样是圆形的,所以我假设,我必须提供我自己的具有透明度的圆形图像。我尝试加载一个透明的圆形 PNG 并在 ICredentialProviderCredentiall::GetBitmapValue()
函数中传递相应的 HBITMAP
。不幸的是,PNG 的背景不是透明的,而是白色的。有什么办法可以显示实际的透明度吗?由于HBITMAP
是LogonUI自己绘制的,我无法修改绘制行为。
为了从我的 PNG 资源中创建 HBITMAP
,我使用了以下函数:
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;
}
我还尝试了 GetHBITMAP()
背景颜色参数的其他值,例如 AlphaMask
和 AlphaShift
,但这些都不起作用(相反,白色背景变成黑色)
有什么方法可以实现我的目标吗?
最新的 Credential Provider Technical Reference(在 MSDN 上不容易找到)实际上说明了平铺图像的问题所在:
In Windows 10, the selected User/V1/PLAP credential provider has an image size of 192x192. The ones on the bottom left list is of 48x48. Note LogonUI uses circular image for user and square image for V1/PLAP according to the new design direction. The image size of V2 Credential Provider tile under a selected user is 48x48.
如果我正确阅读了文档,那么挑战一定是以某种方式让 LogonUI 相信它是一个用户而不是 V1/PLAP,我认为这可以通过在 GetSerialization 调用中返回一个虚拟用户来实现。