Exemplo n.º 1
0
        public void btnSetting_Click(object sender, EventArgs e)
        {
            AvatarCanvas canvas = new AvatarCanvas();

            canvas.LoadZ();
            canvas.LoadActions();
            canvas.LoadEmotions();

            /*
             * cmbAction.Items.Clear();
             * foreach (var action in canvas.Actions)
             * {
             *  ComboItem cmbItem = new ComboItem(action.Name);
             *  switch (action.Level)
             *  {
             *      case 0:
             *          cmbItem.FontStyle = System.Drawing.FontStyle.Bold;
             *          cmbItem.ForeColor = Color.Indigo;
             *          break;
             *
             *      case 1:
             *          cmbItem.ForeColor = Color.Indigo;
             *          break;
             *  }
             *  cmbAction.Items.Add(cmbItem);
             * }*/

            canvas.ActionName       = "stand1";
            canvas.EmotionName      = "default";
            canvas.TamingActionName = "stand1";
            AddPart(canvas, "Character\\00002000.img");
            AddPart(canvas, "Character\\00012000.img");
            AddPart(canvas, "Character\\Face\\00020000.img");
            AddPart(canvas, "Character\\Hair\\00030000.img");
            AddPart(canvas, "Character\\Coat\\01040036.img");
            AddPart(canvas, "Character\\Pants\\01060026.img");
            AddPart(canvas, "Character\\Weapon\\01442000.img");
            //AddPart(canvas, "Character\\Weapon\\01382007.img");
            //AddPart(canvas, "Character\\Weapon\\01332000.img");
            //AddPart(canvas, "Character\\Weapon\\01342000.img");

            var faceFrames = canvas.GetFaceFrames(canvas.EmotionName);

            foreach (var action in canvas.Actions)
            {
                break;
                Gif gif          = new Gif();
                var actionFrames = canvas.GetActionFrames(action.Name);
                foreach (var frame in actionFrames)
                {
                    if (frame.Delay != 0)
                    {
                        var bone = canvas.CreateFrame(frame, faceFrames[0], null);
                        var bmp  = canvas.DrawFrame(bone, frame);

                        Point pos = bmp.OpOrigin;
                        pos.Offset(frame.Flip ? new Point(-frame.Move.X, frame.Move.Y) : frame.Move);
                        GifFrame f = new GifFrame(bmp.Bitmap, new Point(-pos.X, -pos.Y), Math.Abs(frame.Delay));
                        gif.Frames.Add(f);
                    }
                }


                var    gifFile  = gif.EncodeGif(Color.Black);
                string fileName = "D:\\ms\\" + action.Name.Replace('\\', '.');
                gifFile.Save(fileName + (gif.Frames.Count == 1 ? ".png" : ".gif"));
                gifFile.Dispose();
            }

            {
                Gif    gif      = CreateKeyDownAction(canvas);
                var    gifFile  = gif.EncodeGif(Color.Transparent, 0);
                string fileName = "D:\\d12";

                if (false)
                {
                    var fd = new System.Drawing.Imaging.FrameDimension(gifFile.FrameDimensionsList[0]);
                    //获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)
                    int count = gifFile.GetFrameCount(fd);
                    for (int i = 0; i < count; i++)
                    {
                        gifFile.SelectActiveFrame(fd, i);
                        gifFile.Save(fileName + "_" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
                    }
                }
                gifFile.Save(fileName + (gif.Frames.Count == 1 ? ".png" : ".gif"));
                gifFile.Dispose();
            }
        }