Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions IconExtractor/IconExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class IconExtractor
#region Fields

private byte[][] iconData = null; // Binary data of each icon.
private Dictionary<int,int> resourceIds = null;

#endregion

Expand Down Expand Up @@ -97,6 +98,17 @@ public Icon GetIcon(int index)
return new Icon(ms);
}

/// <summary>
/// Extracts an icon from the file by resource id.
/// </summary>
/// <param name="resourceId">Zero based resource id of the icon to be extracted.</param>
/// <returns>A System.Drawing.Icon object.</returns>
/// <remarks>Always returns new copy of the Icon. It should be disposed by the user.</remarks>
public Icon GetByResourceId(int resourceId)
{
return GetIcon(resourceIds[Math.Abs(resourceId)]);
}

/// <summary>
/// Extracts all the icons from the file.
/// </summary>
Expand Down Expand Up @@ -153,6 +165,7 @@ private void Initialize(string fileName)
// Enumerate the icon resource and build .ico files in memory.

var tmpData = new List<byte[]>();
var tmpResourceIds = new Dictionary<int,int>();

bool callback(IntPtr h, IntPtr t, IntPtr name, IntPtr l)
{
Expand Down Expand Up @@ -204,6 +217,8 @@ bool callback(IntPtr h, IntPtr t, IntPtr name, IntPtr l)
}

tmpData.Add(((MemoryStream)dst.BaseStream).ToArray());
tmpResourceIds.Add( Math.Abs(name.ToInt32()),tmpData.Count-1);

}

return true;
Expand All @@ -212,6 +227,7 @@ bool callback(IntPtr h, IntPtr t, IntPtr name, IntPtr l)
_ = Core.EnumResourceNames(hModule, RT_GROUP_ICON, callback, IntPtr.Zero);

iconData = tmpData.ToArray();
resourceIds = tmpResourceIds;
}
finally
{
Expand Down
8 changes: 8 additions & 0 deletions IconExtractor/IconExtractor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.