将特定图标大小从流加载到 TIcon 中
我的应用程序下载并显示特定网站的网站图标。我遵循 Bing 的 解决方案 从流中检测图像格式,但是遇到了另一个障碍。假设一个实际的图标图像,代码如下:(
var
icon : TIcon;
begin
icon := TIcon.Create;
try
icon.LoadFromStream( faviconStream );
spFavicon.Glyph.Assign( icon );
finally
icon.Free;
end;
end;
spFavicon是Raize Components的TRzGlyphStatus。它的Glyph属性是TBitmap)
现在,这可以工作,但有时下载的图标包含多个不同尺寸的图像,例如除了预期的 16x16 之外还有 32x32。由于某种原因,控件的 Glyph 属性选择较大的尺寸。
如何仅将 16x16 尺寸加载到 TIcon 中,或从 TIcon 加载到 TBitmap 中?
测试图标:http://www.kpfa.org/favicon.ico
开启编辑:如果可能的话,我宁愿避免首先将图标保存到文件中。
My application downloads and displays favicons for specific websites. I followed Bing's solution for detecting image format from stream, but have hit another snag. Assuming an actual icon image, the code goes like this:
var
icon : TIcon;
begin
icon := TIcon.Create;
try
icon.LoadFromStream( faviconStream );
spFavicon.Glyph.Assign( icon );
finally
icon.Free;
end;
end;
(spFavicon is TRzGlyphStatus from Raize Components. Its Glyph property is a TBitmap)
Now, this works, but sometimes the downloaded icon contains multiple images in different sizes, e.g. 32x32 in addition to the expected 16x16. For some reason the control's Glyph property picks the larger size.
How can I load only the 16x16 size into TIcon, or from TIcon into TBitmap?
Test favicon: http://www.kpfa.org/favicon.ico
On edit: If at all possible, I'd rather avoid saving the icon to a file first.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.ico 文件格式的主要来源位于 MSDN 。你应该能够从这个问题中得到答案。
Graphics.pas 中的
ReadIcon
过程可能有用,但我想您只需要找到 16x16,因为您正在寻找 favicons。如果你想变得非常可爱,你可以将源代码下载到 Firefox 等设备上,然后看看它们是如何处理网站图标的。
The primary source for the file format of an .ico file is on MSDN. You should be able to work it out from this.
The
ReadIcon
procedure in Graphics.pas may be of use but I imagine that you only need to find 16x16 since you are looking for favicons.If you wanted to get really cute, you could download the source to, say, Firefox, and see exactly how they handle favicons.