public WORD Count; // How many images? #region Methods /// <summary> /// Converts the current TAFactory.IconPack.GroupIconDir into TAFactory.IconPack.IconDir. /// </summary> /// <returns>TAFactory.IconPack.IconDir</returns> public IconDir ToIconDir() { IconDir dir = new IconDir(); dir.Reserved = this.Reserved; dir.Type = this.Type; dir.Count = this.Count; return dir; }
/// <summary> /// Loads the icon information from the givin icon into class members. /// </summary> /// <param name="icon">A System.Drawing.Icon object to retrieve the information about.</param> private void LoadIconInfo(Icon icon) { if (icon == null) { throw new ArgumentNullException("icon"); } this.SourceIcon = icon; MemoryStream inputStream = new MemoryStream(); this.SourceIcon.Save(inputStream); inputStream.Seek(0, SeekOrigin.Begin); IconDir dir = Utility.ReadStructure <IconDir>(inputStream); this.IconDir = dir; this.GroupIconDir = dir.ToGroupIconDir(); this.Images = new List <Icon>(dir.Count); this.IconDirEntries = new List <IconDirEntry>(dir.Count); this.GroupIconDirEntries = new List <GroupIconDirEntry>(dir.Count); this.RawData = new List <byte[]>(dir.Count); IconDir newDir = dir; newDir.Count = 1; for (int i = 0; i < dir.Count; i++) { inputStream.Seek(SizeOfIconDir + i * SizeOfIconDirEntry, SeekOrigin.Begin); IconDirEntry entry = Utility.ReadStructure <IconDirEntry>(inputStream); this.IconDirEntries.Add(entry); this.GroupIconDirEntries.Add(entry.ToGroupIconDirEntry(i)); byte[] content = new byte[entry.BytesInRes]; inputStream.Seek(entry.ImageOffset, SeekOrigin.Begin); inputStream.Read(content, 0, content.Length); this.RawData.Add(content); IconDirEntry newEntry = entry; newEntry.ImageOffset = SizeOfIconDir + SizeOfIconDirEntry; MemoryStream outputStream = new MemoryStream(); Utility.WriteStructure <IconDir>(outputStream, newDir); Utility.WriteStructure <IconDirEntry>(outputStream, newEntry); outputStream.Write(content, 0, content.Length); outputStream.Seek(0, SeekOrigin.Begin); Icon newIcon = new Icon(outputStream); outputStream.Close(); this.Images.Add(newIcon); if (dir.Count == 1) { this.BestFitIconIndex = 0; this.Width = entry.Width; this.Height = entry.Height; this.ColorCount = entry.ColorCount; this.Planes = entry.Planes; this.BitCount = entry.BitCount; } } inputStream.Close(); this.ResourceRawData = GetIconResourceData(); if (dir.Count > 1) { this.BestFitIconIndex = GetBestFitIconIndex(); this.Width = this.IconDirEntries[this.BestFitIconIndex].Width; this.Height = this.IconDirEntries[this.BestFitIconIndex].Height; this.ColorCount = this.IconDirEntries[this.BestFitIconIndex].ColorCount; this.Planes = this.IconDirEntries[this.BestFitIconIndex].Planes; this.BitCount = this.IconDirEntries[this.BestFitIconIndex].BitCount; } }