你如何可以访问使用指数从多图标(.ICO)文件图标在C# [英] How can you access icons from a Multi-Icon (.ico) file using index in C#

查看:186
本文介绍了你如何可以访问使用指数从多图标(.ICO)文件图标在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用从ICO文件中的第四图片 C:\Program文件(x86)\Microsoft的Visual Studio 9.0\Common7\VS2008ImageLibrary\\ \\1033\VS2008ImageLibrary\VS2008ImageLibrary\Objects\ico_format\WinVista\Hard_Drive.ico

I want to use the 4th image from the ico file : C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\VS2008ImageLibrary\1033\VS2008ImageLibrary\VS2008ImageLibrary\Objects\ico_format\WinVista\Hard_Drive.ico

如果我看到使用这个图标Windows照片查看,向我展示13个不同的图标。

If I see this icon using Windows Photo Viewer, shows me 13 different icons.

我已经倾倒这个ICO资源文件,我怎么能使用指数retreive所需的图标。

I have dumped this ico in a resource file, how can I retreive the required icon using index.

推荐答案

在WPF中,你可以做这样的事情:

In WPF, you can do something like this:

Stream iconStream = new FileStream ( @"C:\yourfilename.ico", FileMode.Open );
IconBitmapDecoder decoder = new IconBitmapDecoder ( 
        iconStream, 
        BitmapCreateOptions.PreservePixelFormat, 
        BitmapCacheOption.None );

// loop through images inside the file
foreach ( var item in decoder.Frames )
{
  //Do whatever you want to do with the single images inside the file
  this.panel.Children.Add ( new Image () { Source = item } );
}

// or just get exactly the 4th image:
var frame = decoder.Frames[3];

// save file as PNG
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(frame);
using ( Stream saveStream = new FileStream ( @"C:\target.png", FileMode.Create ))
{
  encoder.Save( saveStream );
}

这篇关于你如何可以访问使用指数从多图标(.ICO)文件图标在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆