473,810 Members | 3,102 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
12 2397
Hello Charles,

I suppose you found RotateAt?

Regarding DPI, in Windows it is considered a user-defined setting and not a
property of the system. So it has nothing to do with true DPI, which can
only be determined by having the user run a calibration program, measuring
and entering the true length and height, which you then use to compute
compensating scale factors. For this compensation I would use a
transformation and not PageScale. The compensation would be the last
transformation in your pipeline.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Charles Law" <bl***@nowhere. com> wrote in message
news:uf******** ******@TK2MSFTN GP15.phx.gbl...
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 #11
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
"Frank Hileman" <fr******@no.sp amming.prodiges oftware.com> wrote in message
news:ue******** ******@TK2MSFTN GP14.phx.gbl...
Hello Charles,

I suppose you found RotateAt?

Regarding DPI, in Windows it is considered a user-defined setting and not
a property of the system. So it has nothing to do with true DPI, which can
only be determined by having the user run a calibration program, measuring
and entering the true length and height, which you then use to compute
compensating scale factors. For this compensation I would use a
transformation and not PageScale. The compensation would be the last
transformation in your pipeline.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

"Charles Law" <bl***@nowhere. com> wrote in message
news:uf******** ******@TK2MSFTN GP15.phx.gbl...
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 #12
Rotations are always about the origin. If you use some trick to shift the
origin to the center of your object then that's ok. If you rotate without
being aware of the origin the object usually disappears and is not seen
again for some time.

Think of quadrants. The normal view of a window shows the lower-right
quadrant of the actual drawing surface. A point at 100,100 is rotated about
a point that is -100,-100 from it's real position.

RotateAt actually translates the drawing surface by -x and -y before
rotation and then translates back +x and +y afterwards.

I tend not to use RoteteAt because it puts a hidden step into the equation
that I don't like to think about. I most often explicitly translate back to
the origin, rotate, possibly scale, and then translate back once again.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Charles Law" <bl***@nowhere. com> wrote in message
news:uf******** ******@TK2MSFTN GP15.phx.gbl...
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 24 '05 #13

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
1960
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
1298
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
5978
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
1205
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
2577
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
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
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
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10124
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
6882
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
5550
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
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
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.