Skip to content

Instantly share code, notes, and snippets.

@QyQj
QyQj / BitmapLoader.cs
Created September 28, 2023 06:56
GrayPngBitmapLoader
public class BitmapLoader
{
private static byte[] PNG_IDENTIFIER = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
/// <summary>
/// Loads an image, checks if it is a PNG containing palette transparency, and if so, ensures it loads correctly.
/// The theory can be found at http://www.libpng.org/pub/png/book/chapter08.html
/// </summary>
/// <param name="filename">Filename to load</param>
/// <returns>The loaded image</returns>