グラフィック変換行列のスケールに関係なく、0.5mmの幅で描画するペンを作成する必要があります。これが私がしていることです:
注:サンプルコードは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)では、0.5インチよりもはるかに太いペンが得られます。
私は何が間違っているのですか?GDIで非スケーリングペンを作成する正しい方法は何ですか?