I am writing an Image Viewer in C# .NET for the console. My problem is that the console font characters are not squares. And I'm treating them as pixels, this stretches the images when drawn on screen.
I want to somehow read the font information about the currently used font, with width
, height
etc properties...
I found this answer, but it seems like it just lists all the currently available fonts.
I played around with this code:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct ConsoleFont
{
public uint Index;
public short SizeX, SizeY;
}
[DllImport("kernel32")]
private static extern bool GetConsoleFontInfo(IntPtr hOutput, [MarshalAs(UnmanagedType.Bool)]bool bMaximize, uint count, [MarshalAs(UnmanagedType.LPArray), Out] ConsoleFont[] fonts);
This did not return the specific font used in the current console window.
I still want to use something like the ConsoleFont
struct for storing font properties. But the GetConsoleFontInfo(...)
does not do this as said...
Please if someone knows how to do this, tell me :)