Draw mirrored in C# using System.Drawing.Graphics

Emiswelt picture Emiswelt · Aug 6, 2011 · Viewed 8.1k times · Source

I have written a little helper function which performs some sort of drawing operations, which are rather complex.

I call this function out of another class which sometimes applies transformations to it. Rotating and translating works fine, but now I want to force the helper function to draw the whole thing mirrored over the y-axis.

I tried to use

g.ScaleTransform(0, -1);

before calling the helper function, but it threw an exception.

So, how is it possible to draw mirrored using a System.Drawing.Graphics object?

Answer

max picture max · Aug 6, 2011

You need to call

g.ScaleTransform(1, -1);

Note that now your image will be drawn behind the upper screen edge. To fix it, you need to call g.TranslateTransform before g.ScaleTransform:

g.TranslateTransform(0, YourImageHeightHere);
g.ScaleTransform(1, -1);