I'm writing a simple program in C# and Windows Forms for manipulating pixel art images and i need to scale these images as the resolution of the canvas changes.
I'm drawing the images on a PictureBox and using an Matrix to scale its graphics object to a certain resolution, and i need a method to scale these images correctly in all directions, based on whatever is the new resolution, without making their pixels become blurred, etc.
Here is the method i'm using to scale the graphics:
public void PictureBox_Paint(object sender, PaintEventArgs e)
{
var graphics = e.Graphics;
graphics.MultiplyTransform(ScaleMatrix());
}
public float VirtualWidth = 1024;
public float VirtualHeight = 768;
public Matrix ScaleMatrix()
{
var matrix = new Matrix();
var x = (float) this.PictureBox.Width / VirtualWidth;
var y = (float) this.PictureBox.Height / VirtualHeight;
matrix.Scale(x, y);
return matrix;
}
What would be the correct implementation to achieve this task?