public WORD  ID;             // the ID

        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;
        }
        public WORD  ID;             // the ID

        public IconDirEntry ToIconDirEntry(int imageOffiset)
        {
            var entry = new IconDirEntry();

            entry.Width       = Width;
            entry.Height      = Height;
            entry.ColorCount  = ColorCount;
            entry.Reserved    = Reserved;
            entry.Planes      = Planes;
            entry.BitCount    = BitCount;
            entry.BytesInRes  = BytesInRes;
            entry.ImageOffset = imageOffiset;
            return(entry);
        }
Пример #3
0
        public WORD  ID;             // the ID

        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);
        }
Пример #4
0
        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 = inputStream.Read <IconDir>();

            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 = inputStream.Read <IconDirEntry>();

                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();
                outputStream.Write <IconDir>(newDir);
                outputStream.Write <IconDirEntry>(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;
            }
        }