Make +y UP, Move Origin C# System.Drawing.Graphics

前端 未结 3 1618
礼貌的吻别
礼貌的吻别 2021-01-05 16:10

I want the origin to be at the center of my window.


______________
|     ^      |
|     |      |
|     o----->|
|            |
|____________|

.NET wan

3条回答
  •  爱一瞬间的悲伤
    2021-01-05 16:42

    You can continue using ScaleTransform(1, -1) and reset the current transformation temporarily while drawing your text:

    // Convert the text alignment point (x, y) to pixel coordinates
    PointF[] pt = new PointF[] { new PointF(x, y) };
    graphics.TransformPoints(CoordinateSpace.Device, CoordinateSpace.World, pt);
    
    // Revert transformation to identity while drawing text
    Matrix oldMatrix = graphics.Transform;
    graphics.ResetTransform();
    
    // Draw in pixel coordinates
    graphics.DrawString(text, font, brush, pt[0]);
    
    // Restore old transformation
    graphics.Transform = oldMatrix;
    

提交回复
热议问题