public PeContainer(string filename, ushort groupIconName) { ValidateFilename(filename); // load pe var datafile = PInvoke.LoadDatafile(filename); if (datafile == IntPtr.Zero) throw new Win32Exception("Unable to load datafile", PInvoke.GetLastWin32Exception()); using (var disposableUpdate = new PInvoke.DisposableHandle(datafile, PInvoke.FreeLibrary)) { // load group icon data var groupIconBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.GROUP_ICON, groupIconName); // parse directory from data Directory = new PeDirectory(groupIconBytes); Images = new IconImage[Directory.Entries.Length]; // parse images from data for (var i = 0; i < Directory.Entries.Length; i++) { var imageBytes = PInvoke.LoadResourceBytes(datafile, (ushort)PInvoke.ResourceType.ICON, Directory.Entries[i].Id); Images[i] = new IconImage(imageBytes); } disposableUpdate.SuppressDispose(); } }
public IconImage(IconImage image) { if (image == null) throw new ArgumentNullException("image"); if (image.Data == null) throw new InvalidOperationException("Image Data is null"); Data = image.Data.ToArray(); }
protected IconContainer() { Images = new IconImage[0]; }
private void Parse(Stream icoStream) { Directory = new IcoDirectory(icoStream); Images = new IconImage[Directory.Entries.Length]; for (var i = 0; i < Directory.Entries.Length; i++) Images[i] = new IconImage(icoStream, (int)Directory.Entries[i].ImageOffset, SeekOrigin.Begin, (int)Directory.Entries[i].BytesInRes); }