PKHeX/PKHeX.WinForms/Subforms/Save Editors/Gen5/CGearImage.cs
Kurt 20905cbe67
Add a search interface for visually filtering all slots (#4712)
* Add slot search to box editor
Alt-Click: Clears the current search.
Shift-Click: Jump to the next box with a result.
2026-02-09 22:03:18 -06:00

45 lines
1.4 KiB
C#

using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using PKHeX.Core;
using PKHeX.Drawing;
namespace PKHeX.WinForms;
/// <summary>
/// Utility logic to convert images to C-Gear Backgrounds and reverse.
/// </summary>
public static class CGearImage
{
private const int Width = CGearBackground.Width;
private const int Height = CGearBackground.Height;
/// <summary>
/// Gets the visual image of a <see cref="CGearBackground"/>.
/// </summary>
public static Bitmap GetBitmap(CGearBackground bg)
{
var data = bg.GetImageData();
return ImageUtil.GetBitmap(data, Width, Height);
}
/// <summary>
/// Converts a <see cref="Bitmap"/> to a <see cref="CGearBackground"/>.
/// </summary>
/// <exception cref="ArgumentException"></exception>
public static TiledImageStat GetCGearBackground(Bitmap img, CGearBackground bg)
{
ArgumentOutOfRangeException.ThrowIfNotEqual(img.Width, Width);
ArgumentOutOfRangeException.ThrowIfNotEqual(img.Height, Height);
ArgumentOutOfRangeException.ThrowIfNotEqual((uint)img.PixelFormat, (uint)PixelFormat.Format32bppArgb);
// get raw bytes of image
byte[] data = img.GetBitmapData();
const int bpp = 4;
Debug.Assert(data.Length == Width * Height * bpp);
return bg.SetImageData(data);
}
}