Пример #1
0
        public static Icon Parse(Stream stream)
        {
            if (stream is null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            UnsafeEx.SkipInitIfPossible(out ICONDIR icondir);   // 6 bytes
            stream.SafeRead(UnsafeEx.AsBytes(ref icondir));

            if (icondir.idCount < 0)
            {
                ThrowHelper.ThrowFormatException();
            }

            using var entries = new UnsafeRawArray <ICONDIRENTRY>(icondir.idCount, false);
            stream.SafeRead(entries.AsBytes());

            return(Icon.Create(icondir.idCount, (stream, entries), static (images, state) =>
            {
                var(stream, entries) = state;
                for (int i = 0; i < images.Length; i++)
                {
                    images[i] = ParseImage(stream, entries[i]);
                }
            }));
        }