문제

나는 원점이 내 창의 중앙에 있기를 원합니다.

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

.NET은 왼쪽 상단에 있기를 원합니다.

_____________>
|            |
|            |
|            |
|            |
V____________|

DOT NET과 나는 잘 지내려고 노력하고 있습니다 ..

그래픽 객체 만 사용하는 C# 에서이 작업을 수행하는 방법을 아는 사람이 있습니까?

Graphics.TranslateTransform은 좌표가 거꾸로 뒤집어 지므로 수행하지 않습니다. 이 그래픽을 결합한 Scaletransform (1, -1)은 텍스트가 거꾸로 나타나기 때문에 만족스럽지 않습니다.

도움이 되었습니까?

해결책

하나의 솔루션은 TranslateTransform 속성을 사용하는 것입니다. 그런 다음 Point/Pointf Structs를 사용하는 대신 Point/Pointf에 암시 적 캐스트가있는 FlippedPoint/FlippedPointf Structs를 생성 할 수 있습니다 (그러나 캐스트를 통해 코디는 뒤집 힙니다).

public struct FlippedPoint
{
    public int X { get; set; }
    public int Y { get; set; }

    public FlippedPoint(int x, int y) : this()
    { X = x; Y = y; }

    public static implicit operator Point(FlippedPoint point)
    { return new Point(-point.X, -point.Y); }

    public static implicit operator FlippedPoint(Point point)
    { return new FlippedPoint(-point.X, -point.Y); }
}

다른 팁

계속 사용할 수 있습니다 ScaleTransform(1, -1) 텍스트를 그리는 동안 현재 변환을 일시적으로 재설정합니다.

// 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;

음의 높이로 그래픽 객체를 만들어보십시오. C# 라이브러리를 구체적으로 알지 못하지만이 트릭은 최근 버전의 GDI에서 작동합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top