Skip to content

Instantly share code, notes, and snippets.

@SonoSooS
Created July 9, 2016 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SonoSooS/f7702f099d50f3278c5278f25c15558b to your computer and use it in GitHub Desktop.
Save SonoSooS/f7702f099d50f3278c5278f25c15558b to your computer and use it in GitHub Desktop.
Extracts ctrulib's default_font.bin to a transparent .png file
using System;
using System.IO;
using System.Drawing;
class Program
{
static Color transparent = Color.FromArgb(0, 0, 0, 0);
static Color black = Color.FromArgb(0xFF, 0, 0, 0);
public static void Main(String[] args)
{
using(FileStream fs = File.OpenRead("default_font.bin"))
{
using(BinaryReader br = new BinaryReader(fs))
{
using(FileStream wfs = File.OpenWrite("ctrufont.png"))
{
using(Bitmap bmp = new Bitmap(16 * 8, 16 * 8, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
for(int y = 0; y != 16; y++)
{
for(int x = 0; x != 16; x++)
{
for(int i = 0; i != 8; i++)
{
int b = br.ReadByte();
for(int j = 7; j != -1; j--)
{
bmp.SetPixel((x * 8) + j, (y * 8) + i, (b & 1) == 0 ? transparent : black);
b >>= 1;
}
}
}
}
bmp.Save(wfs, System.Drawing.Imaging.ImageFormat.Png);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment