public ICONDIRENTRY[] ReadIcons()
        {
            ICONDIRENTRY[] icons = null;

            using (BinaryReader r = new BinaryReader(iconFile))
            {
                int idReserved = r.ReadInt16();
                int idType     = r.ReadInt16();
                if ((idReserved != 0) || (idType != 1))
                {
                    throw new Exception("Invalid .ico file format");
                }
                long nitems = r.ReadInt16();

                icons = new ICONDIRENTRY [nitems];

                for (int i = 0; i < nitems; ++i)
                {
                    ICONDIRENTRY entry = new ICONDIRENTRY();

                    entry.bWidth      = r.ReadByte();
                    entry.bHeight     = r.ReadByte();
                    entry.bColorCount = r.ReadByte();
                    entry.bReserved   = r.ReadByte();
                    entry.wPlanes     = r.ReadInt16();
                    entry.wBitCount   = r.ReadInt16();
                    int dwBytesInRes  = r.ReadInt32();
                    int dwImageOffset = r.ReadInt32();

                    /* Read image */
                    entry.image = new byte [dwBytesInRes];

                    long pos = iconFile.Position;
                    iconFile.Position = dwImageOffset;
                    iconFile.Read(entry.image, 0, dwBytesInRes);
                    iconFile.Position = pos;

                    /*
                     * The wPlanes and wBitCount members in the ICONDIRENTRY
                     * structure can be 0, so we set them from the BITMAPINFOHEADER
                     * structure that follows
                     */

                    if (entry.wPlanes == 0)
                    {
                        entry.wPlanes = (short)(entry.image [12] | (entry.image [13] << 8));
                    }
                    if (entry.wBitCount == 0)
                    {
                        entry.wBitCount = (short)(entry.image [14] | (entry.image [15] << 8));
                    }

                    icons [i] = entry;
                }

                return(icons);
            }
        }
Example #2
0
 public ICONDIRENTRY[] ReadIcons()
 {
     ICONDIRENTRY[] result;
     using (BinaryReader binaryReader = new BinaryReader(this.iconFile))
     {
         int num  = (int)binaryReader.ReadInt16();
         int num2 = (int)binaryReader.ReadInt16();
         if (num != 0 || num2 != 1)
         {
             throw new Exception("Invalid .ico file format");
         }
         long           num3  = (long)binaryReader.ReadInt16();
         ICONDIRENTRY[] array = new ICONDIRENTRY[num3];
         int            num4  = 0;
         while ((long)num4 < num3)
         {
             ICONDIRENTRY icondirentry = new ICONDIRENTRY();
             icondirentry.bWidth      = binaryReader.ReadByte();
             icondirentry.bHeight     = binaryReader.ReadByte();
             icondirentry.bColorCount = binaryReader.ReadByte();
             icondirentry.bReserved   = binaryReader.ReadByte();
             icondirentry.wPlanes     = binaryReader.ReadInt16();
             icondirentry.wBitCount   = binaryReader.ReadInt16();
             int num5 = binaryReader.ReadInt32();
             int num6 = binaryReader.ReadInt32();
             icondirentry.image = new byte[num5];
             long position = this.iconFile.Position;
             this.iconFile.Position = (long)num6;
             this.iconFile.Read(icondirentry.image, 0, num5);
             this.iconFile.Position = position;
             if (icondirentry.wPlanes == 0)
             {
                 icondirentry.wPlanes = (short)((int)icondirentry.image[12] | (int)icondirentry.image[13] << 8);
             }
             if (icondirentry.wBitCount == 0)
             {
                 icondirentry.wBitCount = (short)((int)icondirentry.image[14] | (int)icondirentry.image[15] << 8);
             }
             array[num4] = icondirentry;
             num4++;
         }
         result = array;
     }
     return(result);
 }
Example #3
0
 public override void WriteTo(Stream s)
 {
     using (BinaryWriter binaryWriter = new BinaryWriter(s))
     {
         binaryWriter.Write(0);
         binaryWriter.Write(1);
         binaryWriter.Write((short)this.icons.Length);
         for (int i = 0; i < this.icons.Length; i++)
         {
             Win32IconResource win32IconResource = this.icons[i];
             ICONDIRENTRY      icon = win32IconResource.Icon;
             binaryWriter.Write(icon.bWidth);
             binaryWriter.Write(icon.bHeight);
             binaryWriter.Write(icon.bColorCount);
             binaryWriter.Write(0);
             binaryWriter.Write(icon.wPlanes);
             binaryWriter.Write(icon.wBitCount);
             binaryWriter.Write(icon.image.Length);
             binaryWriter.Write((short)win32IconResource.Name.Id);
         }
     }
 }
Example #4
0
        public override void WriteTo(Stream s)
        {
            using (BinaryWriter w = new BinaryWriter(s)) {
                w.Write((short)0);
                w.Write((short)1);
                w.Write((short)icons.Length);
                for (int i = 0; i < icons.Length; ++i)
                {
                    Win32IconResource icon  = icons [i];
                    ICONDIRENTRY      entry = icon.Icon;

                    w.Write(entry.bWidth);
                    w.Write(entry.bHeight);
                    w.Write(entry.bColorCount);
                    w.Write((byte)0);
                    w.Write(entry.wPlanes);
                    w.Write(entry.wBitCount);
                    w.Write((int)entry.image.Length);
                    w.Write((short)icon.Name.Id);
                }
            }
        }
Example #5
0
 public Win32IconResource(int id, int language, ICONDIRENTRY icon) : base(Win32ResourceType.RT_ICON, id, language)
 {
     this.icon = icon;
 }
Example #6
0
	public ICONDIRENTRY[] ReadIcons () {
		ICONDIRENTRY[] icons = null;

		using (BinaryReader r = new BinaryReader (iconFile)) {
			int idReserved = r.ReadInt16 ();
			int idType = r.ReadInt16 ();
			if ((idReserved != 0) || (idType != 1))
				throw new Exception ("Invalid .ico file format");
			long nitems = r.ReadInt16 ();

			icons = new ICONDIRENTRY [nitems];

			for (int i = 0; i < nitems; ++i) {
				ICONDIRENTRY entry = new ICONDIRENTRY ();

				entry.bWidth = r.ReadByte ();
				entry.bHeight = r.ReadByte ();
				entry.bColorCount = r.ReadByte ();
				entry.bReserved = r.ReadByte ();
				entry.wPlanes = r.ReadInt16 ();
				entry.wBitCount = r.ReadInt16 ();
				int dwBytesInRes = r.ReadInt32 ();
				int dwImageOffset = r.ReadInt32 ();

				/* Read image */
				entry.image = new byte [dwBytesInRes];

				long pos = iconFile.Position;
				iconFile.Position = dwImageOffset;
				iconFile.Read (entry.image, 0, dwBytesInRes);
				iconFile.Position = pos;

				/* 
				 * The wPlanes and wBitCount members in the ICONDIRENTRY
				 * structure can be 0, so we set them from the BITMAPINFOHEADER
				 * structure that follows
				 */

				if (entry.wPlanes == 0)
					entry.wPlanes = (short)(entry.image [12] | (entry.image [13] << 8));
				if (entry.wBitCount == 0)
					entry.wBitCount = (short)(entry.image [14] | (entry.image [15] << 8));

				icons [i] = entry;
			}

			return icons;
		}
	}
Example #7
0
	public Win32IconResource (int id, int language, ICONDIRENTRY icon) : base (Win32ResourceType.RT_ICON, id, language) {
		this.icon = icon;
	}