약간 늦게 응답이 하나,하지만 난 구글에서 그것을 발견하기 때문에 "몇 mm 내 그림 상자를에 들어갈 수있는 질문에 대답 할 때 나는 그렇게 할 것이라고 생각? "그것은 그것을하는 방법을 해결할 필요가없는 많은 시간을 저축했을 것입니다. 도로 getBounds 쓸모가 (당신이 ... 픽셀을 원하는 경우)하지만 Graphics.TransformPoints 방법을 사용하여 도면 단위와 표시 화소 사이의 관계를 찾을 수 있습니다 :
private void Form1_Load(object sender, EventArgs e)
{
Bitmap b;
Graphics g;
Size s = pictureBox1.Size;
b = new Bitmap(s.Width, s.Height);
g = Graphics.FromImage(b);
PointF[] points = new PointF[2];
g.PageUnit = GraphicsUnit.Millimeter;
g.PageScale = 1.0f;
g.ScaleTransform(1.0f, 1.0f);
points[0] = new PointF(0, 0);
points[1] = new PointF(1, 1);
g.TransformPoints(CoordinateSpace.Device, CoordinateSpace.Page, points);
MessageBox.Show(String.Format("1 page unit in {0} is {1} pixels",g.PageUnit.ToString(),points[1].X));
points[0] = new PointF(0, 0);
points[1] = new PointF(1, 1);
g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.World, points);
MessageBox.Show(String.Format("1 page unit in {0} is {1} pixels",g.PageUnit.ToString(),points[1].X));
g.ResetTransform();
pictureBox1.Image = b;
SolidBrush brush = new SolidBrush(Color.FromArgb(120, Color.Azure));
Rectangle rectangle = new Rectangle(10, 10, 50, 50);
// Fill in the rectangle with a semi-transparent color.
g.FillRectangle(brush, rectangle);
pictureBox1.Invalidate();
}
이 표시 할 기본 mm를 표시됩니다 픽셀 (3.779527 내 경우) - 세계 좌표는 픽셀 당 1mm이며, 그래픽을 적용하면 변경됩니다 .ScaleTransform.
편집 : 물론 비트 맵을 pictureBox 이미지 속성에 할당하고 필요에 따라 변경할 수 있도록 그래픽 개체를 유지하면 도움이됩니다.
선언의 버그입니다. 인수는 * ref *가 아닌 * ref *입니다. 가장 좋은 방법은 Width/Height를 사용하는 것입니다. –
아니요, 'out'키워드를 사용하려고하면 오류가 발생합니다. 단위를 변환하는 데 거의 어려움이 없지만 작동하면 더 쉬울 것입니다. –