如何在Windows 10凭据提供商上加载透明图像?
我正在尝试将图像作为瓷砖加载在Windows 10凭据提供商上,该凭据最初写在Windows 7上。但是现在Windows 10上的图像是一个圆而不是正方形,并且希望使圆形的边缘透明。我已经使用了BMP映像,但它不起作用,因此我尝试加载边缘上透明的PNG文件,但这也不起作用。
我已经使用以下代码加载PNG文件和文件加载,但它仅显示为黑色或白色背景,而不是透明的(资源ID是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;
}
最初,我是在使用它来加载BMP文件,但BMP并不真正支持透明度(在这种情况下,IDB_TILE_IMAGE是BMP文件):
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;
}
有关如何在Windows 10凭据提供者上制作透明图像的任何想法,以便我可以显示图像透明透明边缘?我正在寻找的不是一个正方形的图像作为瓷砖加载,而是一个实际的圆形图像,可以匹配Windows 10的Microsoft图像。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论