Microsoft.Maui.Graphics
Microsoft.Maui.Graphics copied to clipboard
[Bug] Concatenating an AffineTransform has no effect on Android
I've been using a MAUI GraphicsView to experiment with the AffineTransform class on Android. Long story short is whenever you concatenate your AffineTransform onto the canvas, then draw an object, you get a blank canvas.
Looking at the source code, it looks like the implementation is unfinished.
Take the following code that draws an 11-pointed star centred at (0,0):
PathF path = new PathF();
for (int i = 0; i < 11; i++)
{
double angle = 5 * i * 2 * Math.PI / 11;
PointF point = new PointF(100 * (float)Math.Sin(angle), -100 * (float)Math.Cos(angle));
if (i == 0)
path.MoveTo(point);
else
path.LineTo(point);
}
canvas.FillColor = Colors.Red;
canvas.Translate(150, 150);
canvas.FillPath(path);
It has to be translated to fully appear on the screen. Trying the same with an AffineTransform yields a blank canvas:
PathF path = new PathF();
for (int i = 0; i < 11; i++)
{
double angle = 5 * i * 2 * Math.PI / 11;
PointF point = new PointF(100 * (float)Math.Sin(angle), -100 * (float)Math.Cos(angle));
if (i == 0)
path.MoveTo(point);
else
path.LineTo(point);
}
canvas.FillColor = Colors.Red;
AffineTransform transform = new AffineTransform();
transform.SetToTranslation(150, 150);
canvas.ConcatenateTransform(transform);
canvas.FillPath(path);