I answered this question a little late, but I thought I would do it because I found it on Google, trying to answer the question “how many mm can I insert in my picture box?”, This would save me a lot of time, no need to understand , how to do it!. GetBounds is useless (if you want it in pixels ...), but you can find the relationship between drawing units and display pixels using the Graphics.TransformPoints method:
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);
This will display the main millimeter for displaying pixels (3.779527 in my case) - the world coordinates are 1 mm per pixel, this will change if you apply graphics.ScaleTransform.
Edit: Of course, this helps if you assign a bitmap to the pictureBox image property (and save the Graphics object to allow changes as needed).
source share