public Bitmap GetFrame(Heroes3Master master)
        {
            if (frames == null || CurrentFrame >= frames.Length)
            {
                return(null);
            }

            if (frames[CurrentFrame] == null)
            {
                var bmp         = creatureAnimation.GetSprite(SPRITES_INDEX, CurrentFrame);
                int castleIndex = GetBackgroundIndex(CreatureIndex);

                if (backgrounds == null)
                {
                    backgrounds = new Bitmap[master.CastlesCount + 1];
                }

                if (backgrounds[castleIndex] == null)
                {
                    backgrounds[castleIndex] = master.ResolveWith(backgroundNames[castleIndex]).GetBitmap();
                }

                Point pt;
                Size  size;
                ComputeSpriteParameters(creatureAnimation.headers[SPRITES_INDEX], out pt, out size);
                // var sw = Stopwatch.StartNew();
                frames[CurrentFrame] = DrawTransparent(backgrounds[castleIndex], bmp, pt, size);
                //fullTime += sw.ElapsedMs();
                using (var g = Graphics.FromImage(frames[CurrentFrame]))
                    g.DrawRectangle(Pens.Black, 0, 0, 100 - 1, 130 - 1);
            }

            return(frames[CurrentFrame]);
        }
 private void button4_Click(object sender, EventArgs e)
 {
     if (lbFiles.SelectedIndex != -1)
     {
         FatRecord rec = selectedLodFile[lbFiles.SelectedItem.ToString()];
         if (rec.Extension == "TXT" || rec.Extension == "ZBK")
         {
             rtbMain.Text = Encoding.Default.GetString(rec.GetRawData());
         }
         else if (rec.Extension == "PCX")
         {
             bmp = rec.GetBitmap();
             Invalidate();
         }
         else if (rec.Extension == "DEF")
         {
             def = rec.GetDefFile();
             bmp = def.GetSprite(0, 0);
             lbDecomposed.Items.Clear();
             for (int i = 0; i < def.BlockCount; i++)
             {
                 lbDecomposed.Items.AddRange(def.headers[i].Names);
             }
         }
     }
 }