Esempio n. 1
0
        private IEnumerable <GameIcon> LoadImages(Atlas atlas, Bitmap bitmap)
        {
            List <GameIcon> icons = new List <GameIcon>();

            foreach (Frame frame in atlas.frames)
            {
                if (frame.w == 0 || frame.h == 0)
                {
                    continue;
                }

                Bitmap   bmp = new Bitmap((int)frame.w, (int)frame.h);
                Graphics g   = Graphics.FromImage(bmp);

                Rectangle toDraw = new Rectangle(0, 0, (int)frame.w, (int)frame.h);

                g.Clear(Color.Transparent);
                g.DrawImage(bitmap, toDraw, frame.x, frame.y, frame.w, frame.h, GraphicsUnit.Pixel);
                g.Dispose();

                GameIcon icon = new GameIcon(frame.name, bmp);
                icons.Add(icon);
            }

            bitmap.Dispose();

            return(icons.ToArray());
        }
        private GameIcon[] LoadImages(string xmlPath)
        {
            try
            {
                Atlas atlas = XmlUtilities <Atlas> .Deserialize(xmlPath);

                string          path   = Path.Combine(Config.HglDir, atlas.file);
                Bitmap          bitmap = new Bitmap(path);
                List <GameIcon> icons  = new List <GameIcon>();

                foreach (Frame frame in atlas.frames)
                {
                    if (frame.w != 0 && frame.h != 0)
                    {
                        Bitmap   bmp = new Bitmap((int)frame.w, (int)frame.h);
                        Graphics g   = Graphics.FromImage(bmp);

                        Rectangle toDraw = new Rectangle(0, 0, (int)frame.w, (int)frame.h);

                        g.Clear(Color.Transparent);
                        g.DrawImage(bitmap, toDraw, frame.x, frame.y, frame.w, frame.h, GraphicsUnit.Pixel);
                        g.Dispose();

                        GameIcon icon = new GameIcon(bmp, frame.name);
                        icons.Add(icon);

                        //bmp.Save(@"F:\icons\" + frame.name + ".bmp");
                    }
                }

                return(icons.ToArray());
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        private GameIcon[] LoadImages(string xmlPath)
        {
            try
            {
                Atlas atlas = XmlUtilities<Atlas>.Deserialize(xmlPath);

                string path = Path.Combine(Config.HglDir, atlas.file);
                Bitmap bitmap = new Bitmap(path);
                List<GameIcon> icons = new List<GameIcon>();

                foreach (Frame frame in atlas.frames)
                {
                    if (frame.w != 0 && frame.h != 0)
                    {
                        Bitmap bmp = new Bitmap((int)frame.w, (int)frame.h);
                        Graphics g = Graphics.FromImage(bmp);

                        Rectangle toDraw = new Rectangle(0, 0, (int)frame.w, (int)frame.h);

                        g.Clear(Color.Transparent);
                        g.DrawImage(bitmap, toDraw, frame.x, frame.y, frame.w, frame.h, GraphicsUnit.Pixel);
                        g.Dispose();

                        GameIcon icon = new GameIcon(bmp, frame.name);
                        icons.Add(icon);

                        //bmp.Save(@"F:\icons\" + frame.name + ".bmp");
                    }
                }

                return icons.ToArray();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }