I am drawing a series of Points using the Graphics class. I am reading from a Point array. For whatever reason the rendered image is upside down (flipped on the X axis). Is there a simple way to tell the Graphics class to draw “upside down” ? Many thanks.
Share
You should note that the default orientation or direction of graphics in most drawing systems is from top of display to the bottom of the display. To compensate for this, you need to know the intended height of your viewing area, and then subtract your coordinates from that height. This will reverse the orientation, and set your figures relative to the bottom of the viewing area.
Let’s say you have two points specified as <x,y> and a viewport that is 300 (w) x 200 (h).
When drawing in the viewing area, <x, y> will get mapped to <x, 200-y>. This gives us the following points.
There are also mechanisms to switch the mapping mode to Cartesian style coordinates, which will probably match your source data, but is usually avoided because it will remap everything else that has already compensated for the default orientation.
The SetMapMode() function in Windows can be used for this purpose if this is what you really wish.
SetMapMode() @ MSDN
Here’s the P/Invoke signature of the function. (from
pinvoke.net: setmapmode (gdi32) )
edit:
There’s one more way to accomplish this, which I personally haven’t tried.
Graphics.TransformPoints Method @ MSDN
This allows you to specify coordinate systems, and the Graphics object will do the mapping for you. In your case, you may wish to call it with CoordinateSpace.World or CoordinateSpace.Page as the first argument, and CoordinateSpace.Device as the second.