private static SpritesContent CropSpritesheet(Image image) { try { var width = image.Width / 16; var height = image.Height / 16; var spritecontent = new SpritesContent() { Width = width, Height = height, Image = new Image[width, height] }; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { spritecontent.Image[x, y] = new Bitmap(16, 16); var graphics = Graphics.FromImage(spritecontent.Image[x, y]); graphics.DrawImage(image, new Rectangle(0, 0, 16, 16), new Rectangle(x * 16, y * 16, 16, 16), GraphicsUnit.Pixel); graphics.Dispose(); } } return(spritecontent); } catch (Exception e) { App.Error(e); } return(null); }
private void SpritesheetForm_Load(object sender, EventArgs e) { _spritedatas = new Dictionary <int, SpriteData>(); _sprites = Manager.Spritesheets[File]; Width = _sprites.Width * 17 * 2 + X_MAGIC_NUMBER; Height = _sprites.Height * 17 * 2 + Y_MAGIC_NUMBER; if (Width >= MAX_SIZE) { Width = MAX_SIZE; } if (Height >= MAX_SIZE) { Height = MAX_SIZE; } var id = 0; for (var x = 0; x < _sprites.Width; x++) { for (var y = 0; y < _sprites.Height; y++) { var image = _sprites.Image[x, y]; var spritepallete = new SpritePallete() { Id = id, Location = new Point(2 + x * 33, 2 + y * 33), Name = "spritepallete", Size = new Size(33, 33), TabIndex = 2, Image = image }; spritepallete.Action = () => Invoke((MethodInvoker) delegate() { var spritedata = _spritedatas[spritepallete.Id]; X = spritedata.X; Y = spritedata.Y; Image = spritedata.Image; DialogResult = DialogResult.OK; }); _spritedatas.Add(id, new SpriteData() { X = x, Y = y, Image = image }); Controls.Add(spritepallete); id++; } } Text = $"Spritesheet: '{File}'."; CenterToScreen(); }