mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-03 12:07:07 -05:00
* Add slot search to box editor Alt-Click: Clears the current search. Shift-Click: Jump to the next box with a result.
45 lines
1.4 KiB
C#
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);
|
|
}
|
|
}
|