Exemple #1
0
 private void createIconResources(ResImageGroupData idata, byte[] iconbytes)
 {
     //now we've re-created the .ico file as a memory stream
     //extract each icon from it by the icon dimensions from the data directory
     MemoryStream ms = new MemoryStream(iconbytes);
     ResData image = null;
     for (int i = 0; i < idata.entries.Count; i++)
     {
         ResImageGroupDataEntry ientry = idata.entries[i];
         ms.Position = 0;
         Icon iconRes = new Icon(ms, (int)ientry.bWidth, (int)ientry.bHeight);       //get the icon
         ientry.image = iconRes;                                                      //link it to this res obj
         foreach (ResData imagedata in iconItems)
         {
             if (imagedata.id == ientry.nID)
             {
                 image = imagedata;
                 break;
             }
         }
         //and add it to the ICON resource list as well
         if (image != null)
         {
             addIcon(image.id, image.name, image.lang, iconRes);
             getDataItem(icons, image.id, image.name).getItem(image.lang).dataBuf = image.data;
         }
     }
 }
Exemple #2
0
//- icon loading --------------------------------------------------------------

        //we create an .ico file in memory for icon resources
        private byte[] buildIconFile(ResImageGroupData idata)
        {
            //build .ico file header
            byte[] hdrbytes = { 0, 0, 1, 0, 0, 0 };
            hdrbytes[4] = (byte)(idata.entries.Count % 0x100);
            hdrbytes[5] = (byte)(idata.entries.Count / 0x100);

            //build .ico data directory
            int datapos = 6 + (0x10 * idata.entries.Count);
            byte[] dirbytes = new byte[0x10 * idata.entries.Count];
            int dirpos = 0;
            for (int i = 0; i < idata.entries.Count; i++)
            {
                ResImageGroupDataEntry ientry = idata.entries[i];
                dirbytes[dirpos++] = (byte)ientry.bWidth;
                dirbytes[dirpos++] = (byte)ientry.bHeight;
                dirbytes[dirpos++] = (byte)ientry.bColorCount;
                dirbytes[dirpos++] = 0;
                dirbytes[dirpos++] = (byte)(ientry.wPlanes % 0x100);
                dirbytes[dirpos++] = (byte)(ientry.wPlanes / 0x100);
                dirbytes[dirpos++] = (byte)(ientry.wBitCount % 0x100);
                dirbytes[dirpos++] = (byte)(ientry.wBitCount / 0x100);
                byte[] sizebytes = BitConverter.GetBytes(ientry.dwBytesInRes);
                Array.Copy(sizebytes, 0, dirbytes, dirpos, 4);
                byte[] posbytes = BitConverter.GetBytes(datapos);
                Array.Copy(posbytes, 0, dirbytes, dirpos + 4, 4);
                dirpos += 8;
                datapos += (int)ientry.dwBytesInRes;
            }

            byte[] iconbytes = new byte[datapos];                       //total .ico data buf
            Array.Copy(hdrbytes, 0, iconbytes, 0, 6);
            Array.Copy(dirbytes, 0, iconbytes, 6, dirbytes.Length);     //copy the .ico header to it

            //append icon data for each icon in directory
            datapos = 6 + (0x10 * idata.entries.Count);
            ResData image = null;
            for (int i = 0; i < idata.entries.Count; i++)
            {
                ResImageGroupDataEntry ientry = idata.entries[i];
                foreach (ResData imagedata in iconItems)                 //find the matching icon data
                {
                    if (imagedata.id == ientry.nID)
                    {
                        image = imagedata;
                        break;
                    }
                }
                if (image != null)
                {
                    Array.Copy(image.data, 0, iconbytes, datapos, image.data.Length);     //and add it to the data buf
                    datapos += image.data.Length;
                }
            }
            return iconbytes;
        }
Exemple #3
0
 public static ResImageGroupDataEntry parseData(BinaryIn src)
 {
     ResImageGroupDataEntry cgdata = new ResImageGroupDataEntry();
     cgdata.bWidth = src.getOne();
     cgdata.bHeight = src.getOne();
     cgdata.bColorCount = src.getOne();
     uint res = src.getOne();
     cgdata.wPlanes = src.getTwo();
     cgdata.wBitCount = src.getTwo();
     cgdata.dwBytesInRes = src.getFour();
     cgdata.nID = src.getTwo();
     cgdata.image = null;
     return cgdata;
 }
Exemple #4
0
 public static ResImageGroupData parseData(byte[] resdata)
 {
     ResImageGroupData igdata = new ResImageGroupData();
     BinaryIn src = new BinaryIn(resdata);
     uint res = src.getTwo();                
     uint type = src.getTwo();
     int count = (int)src.getTwo();
     igdata.entries = new List<ResImageGroupDataEntry>(count);
     for (int i = 0; i < count; i++)
     {
         ResImageGroupDataEntry igentry = ResImageGroupDataEntry.parseData(src);
         igdata.entries.Add(igentry);
     }
     return igdata;
 }
Exemple #5
0
//- cursor loading ------------------------------------------------------------

        //the C# Cursor class is limited for displaying as an image, so we use an Icon obj instead
        //we create an .ico file in memory for cursor resources
        private byte[] buildCursorFile(ResImageGroupData idata, int entrynum)
        {
            //build .ico file header
            byte[] hdrbytes = { 0, 0, 1, 0, 1, 0 };

            //build .ico data directory for a single cursor resource
            int datapos = 0x16;
            byte[] dirbytes = new byte[0x10];
            int dirpos = 0;
            ResImageGroupDataEntry ientry = idata.entries[entrynum];
            dirbytes[dirpos++] = (byte)ientry.bWidth;
            dirbytes[dirpos++] = (byte)ientry.bWidth;           //square icon
            dirbytes[dirpos++] = 2;                             //monochrome
            dirbytes[dirpos++] = 0;
            dirbytes[dirpos++] = 1;
            dirbytes[dirpos++] = 0;
            dirbytes[dirpos++] = 1;
            dirbytes[dirpos++] = 0;
            uint bsize = ientry.dwBytesInRes - 4;
            byte[] sizebytes = BitConverter.GetBytes(bsize);
            Array.Copy(sizebytes, 0, dirbytes, dirpos, 4);
            byte[] posbytes = BitConverter.GetBytes(datapos);
            Array.Copy(posbytes, 0, dirbytes, dirpos + 4, 4);
            dirpos += 8;
            datapos += (int)ientry.dwBytesInRes;            

            byte[] cursorbytes = new byte[datapos];                       //total .cur data buf
            Array.Copy(hdrbytes, 0, cursorbytes, 0, 6);
            Array.Copy(dirbytes, 0, cursorbytes, 6, 0x10);                //copy the .cur header to it

            //append cursor data for each icon in directory
            ResData image = null;
            foreach (ResData imagedata in cursorItems)                 //find the matching cursor data
            {
                if (imagedata.id == ientry.nID)
                {
                    image = imagedata;
                    break;
                }
            }
            if (image != null)
            {
                Array.Copy(image.data, 4, cursorbytes, 0x16, image.data.Length - 4);     //and add it to the data buf, skip the hotspot bytes
            }
            return cursorbytes;
        }
Exemple #6
0
 private void createCursorResources(ResImageGroupData idata, byte[] cursorbytes, int entrynum)
 {
     //get the cursor image from the .ico file we've created in memory
     MemoryStream ms = new MemoryStream(cursorbytes);
     ms.Position = 0;
     Icon curRes = new Icon(ms);                                     //get the cursor
     ResImageGroupDataEntry ientry = idata.entries[entrynum];
     ientry.image = curRes;                                          //link it to this res obj
     ResData image = null;
     foreach (ResData curdata in cursorItems)
     {
         if (curdata.id == ientry.nID)
         {
             image = curdata;
             break;
         }
     }
     //and add it to the CUSROR resource list as well
     if (image != null)
     {
         addCursor(image.id, image.name, image.lang, curRes);
         getDataItem(cursors, image.id, image.name).getItem(image.lang).dataBuf = image.data;
     }
 }