C# GDI+ SetMapMode

本文关键字:SetMapMode GDI+ | 更新日期: 2023-09-27 18:13:15

我似乎在c#中实现SetMapMode有一些问题。我不是c#专家,所以看到错误我并不太惊讶。即使认为编译是好的DrawLine抛出InvalidOperationException。有什么想法吗?

[DllImport("gdi32.dll")]
static extern int SetMapMode(IntPtr hdc, int fnMapMode);
myPen = new Pen(Color.Black, 1);
formGraphics = envMap.CreateGraphics();
IntPtr hdc = formGraphics.GetHdc();
SetMapMode(hdc, 3); // MM_LOMETRIC
formGraphics.DrawLine(myPen, (2 * rect.Right - 60) - 15, 8, (2 * rect.Right - 60), 0);
formGraphics.DrawLine(myPen, (2 * rect.Right - 60), 0, (2 * rect.Right - 60) - 15, -8);

Thanks in advance

C# GDI+ SetMapMode

最接近的是在Graphics对象上设置PageUnit。从我所看到的,没有相当于MM_LOMETRIC的,但有Millimeter

您可能会将其与ScaleTransform结合使用以获得所需的效果。