473,395 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ScaleX alternative

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.
Nov 21 '05 #1
5 8395
Oops hit enter too soon... obviously MillimetersFromPixels will Return
(Pixels / sgDpiX) * 25.4

Nov 21 '05 #2

Larry Lard wrote:
Oops hit enter too soon... obviously MillimetersFromPixels will Return (Pixels / sgDpiX) * 25.4


Or maybe I actually hit Cancel! In which case the above will make no
sense!

What was in my lost post is this:

All I could find of relevance was that the Graphics object has a DpiX
property that returns the dots (pixels for a screen) per inch. So if
you have a Windows Form, add a

Private sgDpiX As Single

then during the form startup do

sgDpiX = Me.CreateGraphics().DpiX

then you can have a function

Private Function MillimetersFromPixels(Pixels As Integer) As Double
Return (Pixels / sgDpiX) * 25.4
End Function

--
Larry Lard
Replies to group please

Nov 21 '05 #3
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.

Nov 21 '05 #4
Thanks everyone

"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.

Nov 21 '05 #5
This is very helpful, thankyou.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eW*************@TK2MSFTNGP15.phx.gbl...
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.


Nov 21 '05 #6

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

Similar topics

46
by: Robin Becker | last post by:
It seems that the rotor module is being deprecated in 2.3, but there doesn't seem to be an obvious alternative. I'm using it just for obfuscation. It seems we have ssl available in 2.3 for sockets,...
99
by: Paul McGuire | last post by:
There are a number of messages on the python-dev mail list that indicate that Guido is looking for some concensus to come from this list as to what *one* alternative syntax for decorators we would...
28
by: Paul McGuire | last post by:
Well, after 3 days of open polling, the number of additional votes have dropped off pretty dramatically. Here are the results so far: Total voters: 55 (with 3 votes each) Votes for each choice...
1
by: Bob Smith | last post by:
so is there any alternative ( standard only ) to using in_avail()? I need to poll with given intervals the input stream, and if there is data to be read I want to read it. thank you /B
43
by: Dimitri Debruyne | last post by:
Hi group I am in the process of developing a website in XHTML Strict and CSS. Is there a way to open a link in a new window without the use of frames or Javascript or something ? I didn't find a...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
3
by: Will McGugan | last post by:
Hi, Is there a naming convention regarding alternative constructors? ie static methods where __new__ is called explicity. I use lower_case for methods in general, but thought maybe CamelCase...
0
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or...
11
by: Francine.Neary | last post by:
I've read that as well as "normal" Java-like function definitions, e.g. int main(int argc, char **argv), you can also choose to use an alternative syntax, i.e. int main(argc, argv) int argc;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
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...
0
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,...

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.