private void drawSprite(ref Bitmap canvas, SpriteItem spriteItem) { Graphics g = Graphics.FromImage(canvas); //draw sprite for (int frame = 0; frame < spriteItem.frames; frame++) { for (int cy = 0; cy < spriteItem.height; ++cy) { for (int cx = 0; cx < spriteItem.width; ++cx) { int frameIndex = cx + cy * spriteItem.width + frame * spriteItem.width * spriteItem.height; Bitmap bmp = ImageUtils.getBitmap(spriteItem.getRGBData(frameIndex), PixelFormat.Format24bppRgb, 32, 32); if (canvas.Width == 32) { g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); } else { g.DrawImage(bmp, new Rectangle(Math.Max(32 - cx * 32, 0), Math.Max(32 - cy * 32, 0), bmp.Width, bmp.Height)); } } } } g.Save(); }
private Bitmap getBitmap(SpriteItem spriteItem) { int Width = 32; int Height = 32; if (spriteItem.width > 1 || spriteItem.height > 1) { Width = 64; Height = 64; } Bitmap canvas = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(canvas); //draw sprite for (int frame = 0; frame < spriteItem.frames; frame++) { for (int cy = 0; cy < spriteItem.height; ++cy) { for (int cx = 0; cx < spriteItem.width; ++cx) { int frameIndex = cx + cy * spriteItem.width + frame * spriteItem.width * spriteItem.height; Bitmap bmp = ImageUtils.getBitmap(spriteItem.getRGBData(frameIndex), PixelFormat.Format24bppRgb, 32, 32); if (canvas.Width == 32) { g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); } else { g.DrawImage(bmp, new Rectangle(Math.Max(32 - cx * 32, 0), Math.Max(32 - cy * 32, 0), bmp.Width, bmp.Height)); } } } } g.Save(); return(canvas); }
private Bitmap getBitmap(SpriteItem spriteItem) { int Width = 32; int Height = 32; if (spriteItem.width > 1 || spriteItem.height > 1) { Width = 64; Height = 64; } Bitmap canvas = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(canvas); //draw sprite for (int frame = 0; frame < spriteItem.frames; frame++) { for (int cy = 0; cy < spriteItem.height; ++cy) { for (int cx = 0; cx < spriteItem.width; ++cx) { int frameIndex = cx + cy * spriteItem.width + frame * spriteItem.width * spriteItem.height; Bitmap bmp = ImageUtils.getBitmap(spriteItem.getRGBData(frameIndex), PixelFormat.Format24bppRgb, 32, 32); if (canvas.Width == 32) { g.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)); } else { g.DrawImage(bmp, new Rectangle(Math.Max(32 - cx * 32, 0), Math.Max(32 - cy * 32, 0), bmp.Width, bmp.Height)); } } } } g.Save(); return canvas; }