无论图形转换矩阵的比例如何,我都需要创建一个宽度为0.5毫米的笔。这是我正在做的:GDI中的非缩放笔+
注意:示例代码是C++/CLI但欢迎使用C#的答案。
// assume that g is a Graphics object
int dpi = g->DpiX;
float dotsPerHalfInch = dpi * 0.5;
// to extract scale factor from the transformation matrix...
// create two points distant one unit apart...
array<PointF> ^points = gcnew array<PointF>{
PointF(0.0f, 0.0f), PointF(1.0f, 0.0f)
};
// transform them...
g->Transform->TransformPoints(points);
// get distance after transformation...
float dX = points[1].X - points[0].X;
float dY = points[1].Y - points[0].Y;
float distance = Math::Sqrt(dX * dX + dY * dY);
// reverse the effects of any scale factor in graphics transform
float penWidth = dotsPerHalfInch/distance;
Pen ^halfInchPen = gcnew Pen(Color::Black, penWidth);
似乎并没有在屏幕(96 dpi)的工作......给了我一个像素宽的笔。在PDF打印机上(600 dpi),它使我的笔厚度超过半英寸。
我在做什么错?在GDI中创建非缩放笔的正确方法是什么?
标签C#isn't权。它看起来像C++ – Jehof 2009-08-21 06:42:20
这是C++/CLI ...但欢迎C#答案。 – 2009-08-21 06:55:49
凹凸!颠簸颠簸颠簸! – 2010-02-19 20:13:14