Beispiel #1
0
		public WORD ID;             // the ID

		/// <summary>
		/// Converts the current TAFactory.IconPack.GroupIconDirEntry into TAFactory.IconPack.IconDirEntry.
		/// </summary>
		/// <param name="id">The resource identifier.</param>
		/// <returns>TAFactory.IconPack.IconDirEntry</returns>
		public IconDirEntry ToIconDirEntry(int imageOffiset)
		{
			IconDirEntry entry = new IconDirEntry();
			entry.Width = this.Width;
			entry.Height = this.Height;
			entry.ColorCount = this.ColorCount;
			entry.Reserved = this.Reserved;
			entry.Planes = this.Planes;
			entry.BitCount = this.BitCount;
			entry.BytesInRes = this.BytesInRes;
			entry.ImageOffset = imageOffiset;
			return entry;
		}
        /// <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 = StreamHelper.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 = StreamHelper.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();
                StreamHelper.WriteStructure <IconDir>(outputStream, newDir);
                StreamHelper.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;
            }
        }