mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-22 20:13:06 +00:00
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:
parent
f690f4885c
commit
0ee36a655a
2 changed files with 4 additions and 18 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue