From 0ee36a655aae9984cc0911262f8d9122714e009e Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 21 Jan 2018 17:22:31 -0800 Subject: [PATCH] Simplify bitmap generation stride is bpp*width + padding bytes; 0x20 worked for the old code since 8*4=0x20 (width of tile). --- .../Save Editors/Gen5/CGearExtensions.cs | 18 +----------------- PKHeX.WinForms/Util/ImageUtil.cs | 4 +++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen5/CGearExtensions.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen5/CGearExtensions.cs index ce811bfa4..49789c802 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen5/CGearExtensions.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen5/CGearExtensions.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.Drawing; -using System.Drawing.Imaging; using PKHeX.Core; namespace PKHeX.WinForms @@ -10,22 +9,7 @@ namespace PKHeX.WinForms { public static Bitmap GetBitmap(CGearBackground bg) { - const int Width = CGearBackground.Width; - const int Height = CGearBackground.Height; - Bitmap img = new Bitmap(Width, Height, PixelFormat.Format32bppArgb); - - // Fill Data - using (Graphics g = Graphics.FromImage(img)) - for (int i = 0; i < bg.Map.TileChoices.Length; i++) - { - int x = (i * 8) % Width; - int y = 8 * ((i * 8) / Width); - var tile = bg.Tiles[bg.Map.TileChoices[i] % bg.Tiles.Length]; - var tileData = tile.Rotate(bg.Map.Rotations[i]); - Bitmap b = ImageUtil.GetBitmap(tileData, 8, 8); - g.DrawImage(b, new Point(x, y)); - } - return img; + return ImageUtil.GetBitmap(bg.GetImageData(), CGearBackground.Width, CGearBackground.Height); } public static CGearBackground GetCGearBackground(Bitmap img) { diff --git a/PKHeX.WinForms/Util/ImageUtil.cs b/PKHeX.WinForms/Util/ImageUtil.cs index 05f683ab2..73122a9b0 100644 --- a/PKHeX.WinForms/Util/ImageUtil.cs +++ b/PKHeX.WinForms/Util/ImageUtil.cs @@ -78,8 +78,10 @@ namespace PKHeX.WinForms ptr = bmpData.Scan0; data = new byte[bmp.Width * bmp.Height * 4]; } - public static Bitmap GetBitmap(byte[] data, int width, int height, int stride = 0x20, PixelFormat format = PixelFormat.Format32bppArgb) + public static Bitmap GetBitmap(byte[] data, int width, int height, int stride = -1, PixelFormat format = PixelFormat.Format32bppArgb) { + if (stride == -1 && format == PixelFormat.Format32bppArgb) + stride = 4 * width; // defaults return new Bitmap(width, height, stride, format, Marshal.UnsafeAddrOfPinnedArrayElement(data, 0)); } public static byte[] GetPixelData(Bitmap bitmap)