Martin,
In addition to the other comments.
The Graphics object supports 3 coordinate spaces:
- Device
- Page
- World
Graphics.PageUnit & Graphics.PageScale are used for Page Coordinate
Spaces/Transforms, where you want to convert the units you are drawing with
(millimeters) to the physical units on the output device (pixels).
Graphics.ScaleTransform (along with Graphics.TranslateTransform &
Graphics.RotateTransform) are used for World Coordinate Spaces/Transforms,
which simply is changing your point of view in relation to the drawing, for
example I think of ScaleTransform as Zooming into & out of the image...
For example if the "normal" resolution of my drawing was millimeters I would
use the following to initialize my graphics object:
Dim gr As Graphics
gr.PageUnit = GraphicsUnit.Millimeter
gr.PageScale = 1
This way when ever I call any Draw or Fill method on this Graphics object,
the units I supplied would be in Millimeters, and I don't need to be
concerned with DPI & such...
' Draw a box 50 millimeters wide, 25 millimeters from the top & left
gr.DrawRectangle(Pens.White, 25, 25, 50, 50)
If I wanted to zoom into or out of this drawing, I would use
Graphics.ScaleTransform:
gr.ScaleTransform(1 / 2, 1 / 2)
gr.ScaleTransform(2, 2)
The drawing would first be adjusted by the World Transform (the
ScaleTransform) then it would be adjust by the Page Transform (PageUnit).
The PageScale above is useful when the "normal" resolution is a fraction of
the Unit (for example 100th of an Inch).
gr.PageScale = 0.01
gr.PageUnit = GraphicsUnit.Inch
You can use Graphics.TransformPoints to translate points to & from the
various coordinate spaces:
Dim bm As New Bitmap(100, 100)
Dim gr As Graphics = Graphics.FromImage(bm)
gr.PageScale = 1
gr.PageUnit = GraphicsUnit.Millimeter
Dim origin As New Point(10, 10)
Dim pts() As Point = New Point() {origin}
gr.TransformPoints(Drawing2D.CoordinateSpace.Devic e,
Drawing2D.CoordinateSpace.Page, pts)
Debug.WriteLine(pts(0))
Graphics.TransformPoints is overloaded for both Point & PointF structures.
Watch the parameters to TransformPoints, the order is not what I would
normally expect...
I normally create helper functions that allow my to TransformSizes &
TranformRectangles based on the needs of the project...
I also normally include all the Graphics initialization in a common routine,
so its easier to find...
Charles Petzold's book "Programming Microsoft Windows With Microsoft Visual
Basic .NET - Core Reference" from MS Press includes an extensive section on
how Page & World transforms work.
Hope this helps
Jay
"Martin Horn" <ma****@nospam.mhorn.co.uk> wrote in message
news:uN***************@newsfe1-win.ntli.net...
Hi,
can someone provide a VB .Net equivalent to the following line of code:
Debug.Print ScaleX(10, vbMillimeters, vbPixels) which produces the
result 37.79524
I have an idea that the graphics object ScaleTransform function may be
what I need to use, however I have been unable to locate an example that
either applies to the above or that I can easily understand.
Thanks,
Martin Horn.