/// <summary> /// saves the icon to a stream /// </summary> public unsafe void Save(Stream str) { if (str == null) { throw new ArgumentNullException("str"); } if (_images.Count < 1) { throw new Exception("icon is empty"); } //write file header ICONDIR fileheader = new ICONDIR((short)(_images.Count)); fileheader.Write(str); //write direntries int fileoffset = sizeof(ICONDIR) + _images.Count * sizeof(ICONDIRENTRY); foreach (IconImage img in _images) { ICONDIRENTRY entry = img.GetEntry(); entry.FileOffset = fileoffset; fileoffset += entry.SizeInBytes; entry.Write(str); } //write images foreach (IconImage img in _images) { img.Write(str); } }
private void Load(Stream str) { //read the file header and check ICONDIR fileheader = new ICONDIR(str); if (fileheader.idType != 1) { throw new Exception("this is not an icon file"); } if (fileheader.idCount < 1) { throw new Exception("no iconimages contained"); } //read direntries ICONDIRENTRY[] entries = new ICONDIRENTRY[fileheader.idCount]; for (int i = 0; i < fileheader.idCount; i++) { entries[i] = new ICONDIRENTRY(str); } //read images for (int i = 0; i < fileheader.idCount; i++) { _images.Add(IconImage.FromStream(str)); } }