Exemplo n.º 1
0
        public IconFile(System.IO.Stream s)
        {
            Skybound.Drawing.Design.IconFile.ICONDIR      icondir;
            Skybound.Drawing.Design.IconFile.ICONDIRENTRY icondirentry;

            using (System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(s))
            {
                icondir = new Skybound.Drawing.Design.IconFile.ICONDIR();
                icondir.Read(binaryReader);
                if ((icondir.idReserved != 0) || (icondir.idType != 1))
                {
                    throw new System.Exception("The specified stream did not contain a valid icon.");
                }
                icondirentry   = new Skybound.Drawing.Design.IconFile.ICONDIRENTRY();
                Formats        = new Skybound.Drawing.Design.IconFormat[icondir.idCount];
                IconData       = new System.Collections.Hashtable();
                IconDirEntries = new System.Collections.Hashtable();
                for (int i = 0; (ushort)i < icondir.idCount; i++)
                {
                    icondirentry.Read(binaryReader);
                    Formats[i] = new Skybound.Drawing.Design.IconFormat(new System.Drawing.Size(icondirentry.bWidth, icondirentry.bHeight), GetColorDepth(icondirentry.wBitCount * icondirentry.wPlanes));
                    long l = s.Position;
                    s.Position = (long)icondirentry.dwImageOffset;
                    byte[] bArr = new byte[icondirentry.dwBytesInRes];
                    s.Read(bArr, 0, icondirentry.dwBytesInRes);
                    IconData[Formats[i]]       = bArr;
                    IconDirEntries[Formats[i]] = icondirentry;
                    s.Position = l;
                }
            }
        }
Exemplo n.º 2
0
        public System.Drawing.Icon ToIcon(Skybound.Drawing.Design.IconFormat iconFormat)
        {
            Skybound.Drawing.Design.IconFile.ICONDIR icondir;

            byte[] bArr = (byte[])IconData[iconFormat];
            System.Drawing.Icon icon = null;
            if (bArr != null)
            {
                System.IO.Stream       stream       = new System.IO.MemoryStream();
                System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(stream);
                icondir         = new Skybound.Drawing.Design.IconFile.ICONDIR();
                icondir.idCount = 1;
                icondir.idType  = 1;
                icondir.WriteToStream(binaryWriter);
                Skybound.Drawing.Design.IconFile.ICONDIRENTRY icondirentry = (Skybound.Drawing.Design.IconFile.ICONDIRENTRY)IconDirEntries[iconFormat];
                icondirentry.dwImageOffset = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Skybound.Drawing.Design.IconFile.ICONDIR)) + System.Runtime.InteropServices.Marshal.SizeOf(typeof(Skybound.Drawing.Design.IconFile.ICONDIRENTRY));
                icondirentry.WriteToStream(binaryWriter);
                stream.Write(bArr, 0, bArr.Length);
                stream.Position = (long)0;
                icon            = new System.Drawing.Icon(stream, icondirentry.bWidth, icondirentry.bHeight);
            }
            return(icon);
        }