13
A
回答
5
作为响应的一部分,Win32 GetIconInfo
调用将返回图标的源位图。您可以从中获取图标图像大小。
Dim IconInf As IconInfo
Dim BMInf As Bitmap
If (GetIconInfo(hIcon, IconInf)) Then
If (IconInf.hbmColor) Then ' Icon has colour plane
If (GetObject(IconInf.hbmColor, Len(BMInf), BMInf)) Then
Width = BMInf.bmWidth
Height = BMInf.bmHeight
BitDepth = BMInf.bmBitsPixel
End If
Call DeleteObject(IconInf.hbmColor)
Else ' Icon has no colour plane, image data stored in mask
If (GetObject(IconInf.hbmMask, Len(BMInf), BMInf)) Then
Width = BMInf.bmWidth
Height = BMInf.bmHeight \ 2
BitDepth = 1
End If
End If
Call DeleteObject(IconInf.hbmMask)
End If
8
这里是一个代码C++版本:
struct MYICON_INFO
{
int nWidth;
int nHeight;
int nBitsPerPixel;
};
MYICON_INFO MyGetIconInfo(HICON hIcon);
// =======================================
MYICON_INFO MyGetIconInfo(HICON hIcon)
{
MYICON_INFO myinfo;
ZeroMemory(&myinfo, sizeof(myinfo));
ICONINFO info;
ZeroMemory(&info, sizeof(info));
BOOL bRes = FALSE;
bRes = GetIconInfo(hIcon, &info);
if(!bRes)
return myinfo;
BITMAP bmp;
ZeroMemory(&bmp, sizeof(bmp));
if(info.hbmColor)
{
const int nWrittenBytes = GetObject(info.hbmColor, sizeof(bmp), &bmp);
if(nWrittenBytes > 0)
{
myinfo.nWidth = bmp.bmWidth;
myinfo.nHeight = bmp.bmHeight;
myinfo.nBitsPerPixel = bmp.bmBitsPixel;
}
}
else if(info.hbmMask)
{
// Icon has no color plane, image data stored in mask
const int nWrittenBytes = GetObject(info.hbmMask, sizeof(bmp), &bmp);
if(nWrittenBytes > 0)
{
myinfo.nWidth = bmp.bmWidth;
myinfo.nHeight = bmp.bmHeight/2;
myinfo.nBitsPerPixel = 1;
}
}
if(info.hbmColor)
DeleteObject(info.hbmColor);
if(info.hbmMask)
DeleteObject(info.hbmMask);
return myinfo;
}
相关问题
- 1. GridPanel如何确定大小?
- 2. 如何确定给定标准的连续范围的大小?
- 3. 如何使用标题确定精确的PE图像文件大小?
- 4. 如何减小JCheckBox图标的大小?
- 5. 确定操作栏菜单中图标的正确大小
- 6. 如何确定SmartGWT标签或HTMLFlow的大小以适应内容的大小?
- 7. 如何绘制HICON?
- 8. 确定当前光标的大小
- 9. 如何确定C#对象的大小
- 10. 如何确定AUSampler实例的大小?
- 11. 如何确定嵌套SVG的大小?
- 12. 如何确定WindowsFormsHost的大小?
- 13. GridBagLayout如何确定容器的大小
- 14. 如何在extjs中正确设置按钮的图标大小?
- 15. 如何确定WPF中的光标大小?
- 16. 如何自定义图标图像的大小?
- 17. 使用xslt确定图形的大小
- 18. 确定RecyclerView中视图的大小
- 19. 确定图像文件大小的PHP
- 20. 在Rails中确定图片的大小
- 21. 何处确定UIView大小
- 22. 如何为我的networkx图指定确切的输出大小?
- 23. 如何更改raphael图标的大小?
- 24. 正确绑定到画布对象的大小图标
- 25. Android自适应图标的正确图标大小
- 26. 如何确定图表的大小以始终填充空间
- 27. 如何“滚动”不确定大小的视图?
- 28. 如何确定图片的大小而不用下载(全部)?
- 29. 如何确定缩略图之间的大小(JavaScript/jQuery滑块)?
- 30. Android:如何确定视图的新大小
谢谢,正常工作与我的彩色图标。掩码中“Height = BMInf.bmHeight \ 2”的用途是什么? – Timbo 2009-12-16 09:53:12
@Timbo:参见msdn:ICONINFO,一个单色图标包含hbmMask中的图像和XOR掩码。 – peterchen 2011-01-18 07:35:57