So I've been trying to resize a CustomPainter
and keep the look as if it was pixel art, but I haven't been able to make it.
// for example, I have this widget, that sets an specific size to a CustomPainter,
// in this case width and height are 16
SizedBox(
width: width*scaleFactor,
height: height*scaleFactor,
child: ClipRect(
child: CustomPaint(
size: Size(width*scaleFactor, height*scaleFactor),
painter: MyCustomPainter(scaleFactor),
),
),
);
// and this would be the custom Painter
class MyCustomPainter extends CustomPainter{
final double scaleFactor;
MyCustomPainter(this.scaleFactor);
@override
void paint(Canvas canvas, Size size) {
canvas.scale(scaleFactor);
canvas.drawPaint(Paint()..color = Colors.white70);
canvas.drawLine(const Offset(4,4), const Offset(12,12), Paint()
..color = Colors.black
..style = PaintingStyle.stroke
..strokeWidth = 1
..isAntiAlias = false);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}
if I set the scaleFactor to 1, I get the results I want of course
and if I change the scaleFactor I get something like this:
but what I would actually want it to like like is like this:
I've even tried with a Transform.scale
widget (not even changing FilterQuality
helps) and even setting a scale matrix inside the canvas with canvas.transform()
but I haven't got any good results.