コード例 #1
0
 /// <summary>
 /// 填充指针列表
 /// </summary>
 /// <param name="filepath"></param>
 private void PakImzPngListIndex()
 {
     ListIndexXY = ReadDir();
     if (ListIndexXY != null)
     {
         imzNum = ListIndexXY.Count;
         for (int i = 0; i < imzNum; i++)
         {
             imzPngIndexopr tmppngindex = new imzPngIndexopr();
             if (File.Exists(filepath + string.Format(@"/{0}.png", i)))
             {
                 tmppngindex.X = ListIndexXY[i].x;
                 tmppngindex.Y = ListIndexXY[i].y;
                 tmppngindex.imzPngIndexStart.Add(new imzPngIndexopr.imzPngIndexStartOpr(0, 0));
                 imzPngListIndex.Add(tmppngindex);
             }
             else
             {
                 int tmpFileIndex = 0;
                 while (File.Exists(filepath + string.Format(@"/{0}_{1}.png", i, tmpFileIndex)))
                 {
                     tmppngindex.imzPngIndexStart.Add(new imzPngIndexopr.imzPngIndexStartOpr(0, 0));
                     tmpFileIndex++;
                 }
                 tmppngindex.X = ListIndexXY[i].x;
                 tmppngindex.Y = ListIndexXY[i].y;
                 imzPngListIndex.Add(tmppngindex);
             }
         }
     }
 }
コード例 #2
0
        private void PakImzPngList(string filename)
        {
            PakImzPngListIndex();
            PakImzListIndex();
            if (ListIndexXY != null)
            {
                imzNum = ListIndexXY.Count;
                FileStream   fs = new FileStream(filename, FileMode.Create);
                BinaryWriter br = new BinaryWriter(fs);
                br.Write(imzNum);
                for (int i = 0; i < imzListIndex.Count; i++)
                {
                    br.Write(imzListIndex[i]);
                }
                fs.Seek(imzPngListIndexSize, SeekOrigin.Current);
                for (int i = 0; i < imzNum; i++)
                {
                    byte[] tmpbyte;
                    string tmpfilename;
                    switch (imzPngListIndex[i].imzPngIndexStart.Count)
                    {
                    case 0:
                        imzPngListIndex[i] = new imzPngIndexopr();
                        break;

                    case 1:
                        tmpfilename = string.Format(filepath + string.Format(@"/{0}.png", i));
                        imzPngListIndex[i].imzPngIndexStart = new List <imzPngIndexopr.imzPngIndexStartOpr>();
                        if (!File.Exists(tmpfilename))
                        {
                            tmpfilename = filepath + string.Format(@"/{0}_{1}.png", i, 0);
                        }
                        using (FileStream pngstream = new FileStream(tmpfilename, FileMode.Open))
                        {
                            tmpbyte = new byte[pngstream.Length];
                            pngstream.Read(tmpbyte, 0, (int)pngstream.Length);
                        }
                        imzPngListIndex[i].imzPngIndexStart.Add(new imzPngIndexopr.imzPngIndexStartOpr((int)fs.Position, tmpbyte.Length));
                        fs.Write(tmpbyte, 0, tmpbyte.Length);
                        GC.Collect();
                        break;

                    default:
                        int tmpcount = imzPngListIndex[i].imzPngIndexStart.Count;
                        imzPngListIndex[i].imzPngIndexStart = new List <imzPngIndexopr.imzPngIndexStartOpr>();
                        for (int tmpFileIndex = 0; tmpFileIndex < tmpcount; tmpFileIndex++)
                        {
                            using (FileStream pngstream = new FileStream(filepath + string.Format(@"/{0}_{1}.png", i, tmpFileIndex),
                                                                         FileMode.Open))
                            {
                                tmpbyte = new byte[pngstream.Length];
                                pngstream.Read(tmpbyte, 0, (int)pngstream.Length);
                            }
                            imzPngListIndex[i].imzPngIndexStart.Add(new imzPngIndexopr.imzPngIndexStartOpr((int)fs.Position, tmpbyte.Length));
                            fs.Write(tmpbyte, 0, tmpbyte.Length);
                            GC.Collect();
                        }
                        break;
                    }
                }
                fs.Seek(imzListIndexSize, SeekOrigin.Begin);
                for (int i = 0; i < imzPngListIndex.Count; i++)
                {
                    br.Write(imzPngListIndex[i].X);
                    br.Write(imzPngListIndex[i].Y);
                    br.Write(imzPngListIndex[i].num);
                    for (int j = 0; j < imzPngListIndex[i].imzPngIndexStart.Count; j++)
                    {
                        br.Write(imzPngListIndex[i].imzPngIndexStart[j].StartIndex);
                        br.Write(imzPngListIndex[i].imzPngIndexStart[j].LengthIndex);
                    }
                }
                br.Close();
                fs.Close();
            }
        }