Is GDI+ PageUnit Supposed to be Accurate?

  • Thread starter Thread starter Charles Law
  • Start date Start date
C

Charles Law

If I draw a rectangle, 6 inches by 2 inches, on a user control with a
PageUnit of Inches, I get a rectangle of 7 by 2.2 inches.

Is this what people would expect? I would have hoped that it was at least
scaled consistently.

Charles
 
GDI+ says all monitors are 96 DPI, but not all of them are. That may be
causing what you're seeing. Your measurements would seem to be outside of
that "margin for error" - an extra inch? - but it's the only thing I know of
that would cause the differential.

I have heard of people managing this by drawing a line a certain number of
pixels and asking the user to provide the measurement of said line. From
there - assuming you work entirely in inches (or whatever unit of measure
you choose to have them use) - you could do your own translation of physical
dimensions to pixels. You would have to have them measure in both
directions, and drawing "off the axes" might be tough, but it could be
workable.

I believe you can query the monitor through the Windows API and Interop, but
even if you get the true physical dimensions, I don't think you'll have much
luck making a transformation in GDI+ that will work for you.

HTH

- Scott
 
Hi Scott

Thanks for the reply. I have tried measuring a "standard" rectangle of 100
by 100 mm, and scaling the graphics object with ScaleTransform, and this
corrects the standard rectangle dimensions. However, when I double the size
of the rectangle, the new width is only 195 mm instead of 200 mm. It would
seem that the transformation/scaling is not linear, which makes it
impossible to scale anything correctly.

Charles
 
Hi Cor

Ah yes ... Fergus, dear chap. Where is he now?

I am trying to find a way to scale things reliably, but as I mentioned in my
other reply, the scaling does not appear to be linear.

Any ideas?

Charles
 
Hi Charles,

In my opinion is the answer in the question and the answer Fergus gave?

Never done, however it sound reasonable for me.

Cor
 
It's my understanding that, no matter what your monitor is set at, GDI+ in
..NET will return 96 DPI for any Graphics object created from the screen. So
querying the Graphics object's DPI settings won't get you anywhere - they
will say 96, and your math still won't be right. That's why I said you
should use the Windows API (via Interop) to get the physical dimensions (and
any DPI that GDI might tell you, which could - but is not likely to - be
different.)

I would guess the errors in scaling are related to rounding, so you may not
be able to get an exact solution that fits all cases. Is it of vital
importance that 200mm is 200mm (and not 195)? I realize that may be a dumb
question, but we might not be able to get you there from here...

- Scott
 
Is it of vital importance that 200mm is 200mm (and not 195)?

It's not critical for its own sake, but I had hoped to provide a zoom for
the elements that are being drawn by using ScaleTransform. If the x and y
scale factors are the same then the object being zoomed changes its aspect
ratio as it is enlarged, and it is very obvious. With no rule to follow and
no point of reference I can't zoom the object proportionally.

Here's an example; I have abandoned changing PageUnit, and am leaving it set
to the default (pixels), because it seems to be more trouble than it's
worth. I draw a rectangle of 200 by 200. This equates to

64 x 60 mm

Applying a scale transform of (2, 2) the new measurement is

125 x 118 mm

This is actually a scale of 1.95/1.96, which I suppose is close enough, but
it's not 2. Anyway, I shall persevere.

Thanks for the replies.

Charles
 
Well - you're getting into areas where my knowledge is a little fuzzy.
Perhaps Bob Powell or Frank Hilleman will chime in here - they are much more
adept in these areas than I. But given the nature of pixels to physical
measurements, taking into account the monitor resolution, screen size, type,
and manufacturer's quirks, I'm not sure how close you'll be able to get.

- Scott
 
Hi Frank

I didn't, actually, but I will certainly take a look at it. I think I won't
go to the extent of measuring on-screen to calibrate, but just try to find a
way to ensure that when I do scale an object it retains its aspect ratio.
The most reliable way to do this seems to be to stick with units of pixel,
and not use millimetres or inches.

Charles
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top