Simplify bitmap generation

stride is bpp*width + padding bytes; 0x20 worked for the old code since
8*4=0x20 (width of tile).
This commit is contained in:
Kurt 2018-01-21 17:22:31 -08:00
parent f690f4885c
commit 0ee36a655a
2 changed files with 4 additions and 18 deletions

View file

@ -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)
{

View file

@ -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)