473,799 Members | 3,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is GDI+ PageUnit Supposed to be Accurate?

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
Aug 22 '05 #1
12 2396
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

"Charles Law" <bl***@nowhere. com> wrote in message
news:O5******** ******@TK2MSFTN GP14.phx.gbl...
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

Aug 22 '05 #2
Charles,

The answer you got did remind me what another Englishman once wrote in this
newsgroup.

See the complete thread (although it is only important until the first
answer)
http://groups.google.com/group/micro...4af837e33f202d

(I am waiting)

:-)))

I hope this helps,

Cor
Aug 22 '05 #3
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
"Scott McChesney" <sc************ *********@us.ar my.mil> wrote in message
news:e7******** ******@TK2MSFTN GP15.phx.gbl...
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

"Charles Law" <bl***@nowhere. com> wrote in message
news:O5******** ******@TK2MSFTN GP14.phx.gbl...
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


Aug 22 '05 #4
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
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Charles,

The answer you got did remind me what another Englishman once wrote in
this newsgroup.

See the complete thread (although it is only important until the first
answer)
http://groups.google.com/group/micro...4af837e33f202d

(I am waiting)

:-)))

I hope this helps,

Cor

Aug 22 '05 #5
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
Aug 22 '05 #6
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

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
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

Aug 22 '05 #7
> 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
"Scott McChesney" <sc************ *********@us.ar my.mil> wrote in message
news:uv******** ******@TK2MSFTN GP12.phx.gbl...
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

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
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


Aug 22 '05 #8
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

"Charles Law" <bl***@nowhere. com> wrote in message
news:uC******** ******@TK2MSFTN GP12.phx.gbl...
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
"Scott McChesney" <sc************ *********@us.ar my.mil> wrote in message
news:uv******** ******@TK2MSFTN GP12.phx.gbl...
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

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
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



Aug 23 '05 #9
Hi Scott

I have been playing again, and now have something that takes two radii and
an angle, and draws a filled arc in the position I require. I think that the
rotation does not work as I thought because the centre of rotation is the
origin, and not the centre of my arcs. This makes sense, but does not help
me much.

I have seen Bob's web site, and he observes that transformations are, at
best, not intuitive to follow. It strikes me that GDI+ is very powerful, but
it is all things to all people, and therefore frequently requires quite a
lot of work to make it do what is wanted. Perhaps this another area where
Microsoft could provide more examples/samples to get people started. Just a
thought.

Charles
"Scott McChesney" <sc************ *********@us.ar my.mil> wrote in message
news:us******** ******@TK2MSFTN GP10.phx.gbl...
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

"Charles Law" <bl***@nowhere. com> wrote in message
news:uC******** ******@TK2MSFTN GP12.phx.gbl...
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
"Scott McChesney" <sc************ *********@us.ar my.mil> wrote in message
news:uv******** ******@TK2MSFTN GP12.phx.gbl...
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

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
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



Aug 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
589
by: Bram | last post by:
Hi, i'm experiencing a very weird problem here. I've got a ListView, 4 columns and about 300 items. Nothing to worry about there. Now when I scroll up and down repeatedly using the vertical scrollbar, I see the number of GDI object grow rapidly. Now and then it drops again to about 60 which is reasonable.When this number reaches 10.000, all of a sudden, it turns into 4.294.964.397 (more or less). Running the garbage collector...
6
1959
by: Phillip N Rounds | last post by:
I have an application which is heavily graphics intensive, all the graphics being custom. Scattered throughout by app, I have MyView->OnDraw( this->GetDC() ); Apparently, each call to this->GetDC() creates a GDI object and, 16,000 or so calls to OnDraw() results in the Application hanging because it can no longer create any new GDI objects ( I know, 16,384 )
12
1296
by: Charles Law | last post by:
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
7
5976
by: Marcin Rzeznicki | last post by:
Hello, Do you think it is legitimate practice to mix GDI+ and GDI calls (via Get/ReleaseHDC()) in paint event of a control? I've heard there is possibility of performance loss while "locking" Graphics object which is done as a side-effect to GetHDC() call - could you confirm? Another question that comes to my mind when planning mentioned operation is: if the control painted on uses double-buffering style, will GDI calls make use of "back...
0
1204
by: Rotsey | last post by:
Hi, I have a jpg that i am using asa template using GDI to draw on. I am using paint to look at the jpg and using pixels to determine where I want to draw to with GDI. I changed the graphics unit to pixels like this. e.Graphics.PageUnit = GraphicsUnit.Pixel;
4
4888
nukefusion
by: nukefusion | last post by:
I'm having trouble using MeasureCharacterRanges. If I use it to get the width of the string "TEST" I would expect to get the same width as I would if I used it to get the individual widths of the characters "T", "E", "S", and "T" and then added the resulting values together. The problem is that the two values don't seem to match unless the Graphics.PageUnit is set to Inch. I don't understand why it doesn't work with the default setting of...
1
2576
by: crom | last post by:
Hello everyone! I creating a document using VBNET's "graphics" object and show them in the PictureBox. Here is Sub CreateDoc which draw the document and shortened part of program (mistakes possible because of out IDE editing). My intention is to call CreateDoc again through buttons PrintPreview or Print (I read that this is possible). But calling from PrintPreview Sub (PrnDoc_PrintPage) dont make any "picture" on PrintPreview control. As you...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.