/// <summary> /// Gets a System.Drawing.Icon that represents RT_GROUP_ICON at the givin index from the executable module. /// </summary> /// <param name="index">The index of the RT_GROUP_ICON in the executable module.</param> /// <returns>Returns System.Drawing.Icon.</returns> private Icon GetIconFromLib(int index) { byte[] resourceData = GetResourceData(this.ModuleHandle, this.IconNames[index], ResourceTypes.RT_GROUP_ICON); //Convert the resouce into an .ico file image. using (MemoryStream inputStream = new MemoryStream(resourceData)) using (MemoryStream destStream = new MemoryStream()) { //Read the GroupIconDir header. GroupIconDir grpDir = inputStream.Read <GroupIconDir>(); int numEntries = grpDir.Count; int iconImageOffset = IconInfo.SizeOfIconDir + numEntries * IconInfo.SizeOfIconDirEntry; destStream.Write <IconDir>(grpDir.ToIconDir()); for (int i = 0; i < numEntries; i++) { //Read the GroupIconDirEntry. GroupIconDirEntry grpEntry = inputStream.Read <GroupIconDirEntry>(); //Write the IconDirEntry. destStream.Seek(IconInfo.SizeOfIconDir + i * IconInfo.SizeOfIconDirEntry, SeekOrigin.Begin); destStream.Write <IconDirEntry>(grpEntry.ToIconDirEntry(iconImageOffset)); //Get the icon image raw data and write it to the stream. byte[] imgBuf = GetResourceData(this.ModuleHandle, grpEntry.ID, ResourceTypes.RT_ICON); destStream.Seek(iconImageOffset, SeekOrigin.Begin); destStream.Write(imgBuf, 0, imgBuf.Length); //Append the iconImageOffset. iconImageOffset += imgBuf.Length; } destStream.Seek(0, SeekOrigin.Begin); return(new Icon(destStream)); } }
public DWORD ImageOffset; // Where in the file is this image? public GroupIconDirEntry ToGroupIconDirEntry(int id) { GroupIconDirEntry grpEntry = new GroupIconDirEntry(); grpEntry.Width = this.Width; grpEntry.Height = this.Height; grpEntry.ColorCount = this.ColorCount; grpEntry.Reserved = this.Reserved; grpEntry.Planes = this.Planes; grpEntry.BitCount = this.BitCount; grpEntry.BytesInRes = this.BytesInRes; grpEntry.ID = (short)id; return grpEntry; }
public DWORD ImageOffset; // Where in the file is this image? public GroupIconDirEntry ToGroupIconDirEntry(int id) { GroupIconDirEntry grpEntry = new GroupIconDirEntry(); grpEntry.Width = this.Width; grpEntry.Height = this.Height; grpEntry.ColorCount = this.ColorCount; grpEntry.Reserved = this.Reserved; grpEntry.Planes = this.Planes; grpEntry.BitCount = this.BitCount; grpEntry.BytesInRes = this.BytesInRes; grpEntry.ID = (short)id; return(grpEntry); }
public DWORD ImageOffset; // Where in the file is this image? public GroupIconDirEntry ToGroupIconDirEntry(int id) { var grpEntry = new GroupIconDirEntry(); grpEntry.Width = Width; grpEntry.Height = Height; grpEntry.ColorCount = ColorCount; grpEntry.Reserved = Reserved; grpEntry.Planes = Planes; grpEntry.BitCount = BitCount; grpEntry.BytesInRes = BytesInRes; grpEntry.ID = (short)id; return(grpEntry); }