[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

How to make scale transform not affect line thickness

Ian Post

10/20/2004 1:33:00 PM

Hi all!
I'm using ScaleTransform to implement zoom in/out functionality. I'd
like to have the ScaleTransform only affect the positioning of
endpoints of lines drawn using Graphics.DrawLine, ie. the thickness of
lines should stay constant. Is this possible?
8 Answers

Bob Powell

10/20/2004 1:56:00 PM

0

There are two ways to do this.

First, create pens with a width of -1. Any pen created in this way should
provide a 1 pixel thick line regardless of the page scale settings.

Second, if you must use a line that isn't 1 pixel, scale the pen to be the
reciprocal of the page scale ie pen-scale = 1/page scale.

Hope this helps.

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

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
Bob's Blog: http://bobpowelldotnet.blogspot.co...






"Arkion" <nospam@nowhere.com> wrote in message
news:d0qcn01ovp5kvgm3c3dhbq26ao9vb3pumn@4ax.com...
> Hi all!
> I'm using ScaleTransform to implement zoom in/out functionality. I'd
> like to have the ScaleTransform only affect the positioning of
> endpoints of lines drawn using Graphics.DrawLine, ie. the thickness of
> lines should stay constant. Is this possible?


Ian Post

10/20/2004 3:53:00 PM

0

On Wed, 20 Oct 2004 15:55:55 +0200, "Bob Powell [MVP]"
<bob@_spamkiller_bobpowell.net> wrote:

>There are two ways to do this.
>
>First, create pens with a width of -1. Any pen created in this way should
>provide a 1 pixel thick line regardless of the page scale settings.
>
>Second, if you must use a line that isn't 1 pixel, scale the pen to be the
>reciprocal of the page scale ie pen-scale = 1/page scale.
>
>Hope this helps.

Sure it does! Thanks much!

Gerald Hernandez

10/20/2004 4:15:00 PM

0

As a side note...
I think it was a very good idea for MS to implement the -1 width to be 1
pixel.
I would really like to see them take this further, and make -2 = 2 pixels,
and so on.
In what I do, we use 2 classifications of line weight.
Line Weight = Width of line in pixels at all times, regardless of zoom.
Line Width = Actual width of line proportional to zoom. Wider as you zoom
in, smaller as you zoom out, eventually to nothing.

If I could just use the negative values to represent Weight, it would really
make my life easier.
Or I could be completely off-base here. In fact, I haven't tried a -2 width
so I don't know for certain it doesn't work that way.

Gerald

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%23sgA8yqtEHA.2624@TK2MSFTNGP11.phx.gbl...
> There are two ways to do this.
>
> First, create pens with a width of -1. Any pen created in this way should
> provide a 1 pixel thick line regardless of the page scale settings.
>
> Second, if you must use a line that isn't 1 pixel, scale the pen to be the
> reciprocal of the page scale ie pen-scale = 1/page scale.
>
> Hope this helps.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/gdipl...
>
> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
> Bob's Blog: http://bobpowelldotnet.blogspot.co...
>
>
>
>
>
>
> "Arkion" <nospam@nowhere.com> wrote in message
> news:d0qcn01ovp5kvgm3c3dhbq26ao9vb3pumn@4ax.com...
> > Hi all!
> > I'm using ScaleTransform to implement zoom in/out functionality. I'd
> > like to have the ScaleTransform only affect the positioning of
> > endpoints of lines drawn using Graphics.DrawLine, ie. the thickness of
> > lines should stay constant. Is this possible?
>
>


James Parsly

10/20/2004 4:22:00 PM

0

In this second case, what happens if your transformation is different in the
X and Y directions?

Suppose you do something like this:

Dim g As Graphics = e.Graphics

Dim mypen As New Pen(Color.Red, 2) 'lets be difficult and ask for a thicker
line

g.ScaleTransform(1, 5)

g.DrawLine(mypen, 5, 5, 5, 95)

g.DrawLine(mypen, 5, 5, 95, 5)

g.DrawLine(mypen, 5, 5, 95, 95)

g.DrawLine(mypen, 5, 5, 95, 20)

g.DrawLine(mypen, 5, 5, 95, 20)

g.DrawLine(mypen, 5, 5, 95, 40)

g.DrawLine(mypen, 5, 5, 95, 60)

This produces lines whose width varies depending on what direction they

are drawn. How would you make them all come out the same width?

"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%23sgA8yqtEHA.2624@TK2MSFTNGP11.phx.gbl...
> There are two ways to do this.
>
> First, create pens with a width of -1. Any pen created in this way should
> provide a 1 pixel thick line regardless of the page scale settings.
>
> Second, if you must use a line that isn't 1 pixel, scale the pen to be the
> reciprocal of the page scale ie pen-scale = 1/page scale.
>
> Hope this helps.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/gdipl...
>
> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
> Bob's Blog: http://bobpowelldotnet.blogspot.co...
>
>
>
>
>
>
> "Arkion" <nospam@nowhere.com> wrote in message
> news:d0qcn01ovp5kvgm3c3dhbq26ao9vb3pumn@4ax.com...
> > Hi all!
> > I'm using ScaleTransform to implement zoom in/out functionality. I'd
> > like to have the ScaleTransform only affect the positioning of
> > endpoints of lines drawn using Graphics.DrawLine, ie. the thickness of
> > lines should stay constant. Is this possible?
>
>


James Parsly

10/20/2004 5:35:00 PM

0

-2 seems to give the same results as -1.
"Gerald Hernandez" <Cablewizard@spam_remove@Yahoo.com> wrote in message
news:%23DIVMAstEHA.2536@TK2MSFTNGP11.phx.gbl...
> As a side note...
> I think it was a very good idea for MS to implement the -1 width to be 1
> pixel.
> I would really like to see them take this further, and make -2 = 2 pixels,
> and so on.
> In what I do, we use 2 classifications of line weight.
> Line Weight = Width of line in pixels at all times, regardless of zoom.
> Line Width = Actual width of line proportional to zoom. Wider as you zoom
> in, smaller as you zoom out, eventually to nothing.
>
> If I could just use the negative values to represent Weight, it would
really
> make my life easier.
> Or I could be completely off-base here. In fact, I haven't tried a -2
width
> so I don't know for certain it doesn't work that way.
>
> Gerald
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:%23sgA8yqtEHA.2624@TK2MSFTNGP11.phx.gbl...
> > There are two ways to do this.
> >
> > First, create pens with a width of -1. Any pen created in this way
should
> > provide a 1 pixel thick line regardless of the page scale settings.
> >
> > Second, if you must use a line that isn't 1 pixel, scale the pen to be
the
> > reciprocal of the page scale ie pen-scale = 1/page scale.
> >
> > Hope this helps.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/gdipl...
> >
> > The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> > Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tips...
> > Bob's Blog: http://bobpowelldotnet.blogspot.co...
> >
> >
> >
> >
> >
> >
> > "Arkion" <nospam@nowhere.com> wrote in message
> > news:d0qcn01ovp5kvgm3c3dhbq26ao9vb3pumn@4ax.com...
> > > Hi all!
> > > I'm using ScaleTransform to implement zoom in/out functionality. I'd
> > > like to have the ScaleTransform only affect the positioning of
> > > endpoints of lines drawn using Graphics.DrawLine, ie. the thickness of
> > > lines should stay constant. Is this possible?
> >
> >
>
>


Bob Powell

10/21/2004 11:30:00 AM

0

You could try to set up the matrix for the pen scaling like this...

Dim mx as new Matrix(1.0f/xscale,0,0,1.0f/yscale,0,0)
myPen.Transorm=mx


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

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
Bob's Blog: http://bobpowelldotnet.blogspot.co...






"James Parsly" <japarsly@nospam.tva.gov> wrote in message
news:newscache$wf8w5i$hp7$1@lyris.knx.tva.gov...
> In this second case, what happens if your transformation is different in
the
> X and Y directions?
>
> Suppose you do something like this:
>
> Dim g As Graphics = e.Graphics
>
> Dim mypen As New Pen(Color.Red, 2) 'lets be difficult and ask for a
thicker
> line
>
> g.ScaleTransform(1, 5)
>
> g.DrawLine(mypen, 5, 5, 5, 95)
>
> g.DrawLine(mypen, 5, 5, 95, 5)
>
> g.DrawLine(mypen, 5, 5, 95, 95)
>
> g.DrawLine(mypen, 5, 5, 95, 20)
>
> g.DrawLine(mypen, 5, 5, 95, 20)
>
> g.DrawLine(mypen, 5, 5, 95, 40)
>
> g.DrawLine(mypen, 5, 5, 95, 60)
>
> This produces lines whose width varies depending on what direction they
>
> are drawn. How would you make them all come out the same width?
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:%23sgA8yqtEHA.2624@TK2MSFTNGP11.phx.gbl...
> > There are two ways to do this.
> >
> > First, create pens with a width of -1. Any pen created in this way
should
> > provide a 1 pixel thick line regardless of the page scale settings.
> >
> > Second, if you must use a line that isn't 1 pixel, scale the pen to be
the
> > reciprocal of the page scale ie pen-scale = 1/page scale.
> >
> > Hope this helps.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/gdipl...
> >
> > The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> > Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tips...
> > Bob's Blog: http://bobpowelldotnet.blogspot.co...
> >
> >
> >
> >
> >
> >
> > "Arkion" <nospam@nowhere.com> wrote in message
> > news:d0qcn01ovp5kvgm3c3dhbq26ao9vb3pumn@4ax.com...
> > > Hi all!
> > > I'm using ScaleTransform to implement zoom in/out functionality. I'd
> > > like to have the ScaleTransform only affect the positioning of
> > > endpoints of lines drawn using Graphics.DrawLine, ie. the thickness of
> > > lines should stay constant. Is this possible?
> >
> >
>
>


James Parsly

10/21/2004 2:19:00 PM

0

From this hint, I changed the code as follows:

Dim g As Graphics = e.Graphics

Dim mypen As New Pen(Color.Red, 2)

g.ScaleTransform(2, 5)

mypen.ScaleTransform(0.5F, 0.2F) '<---- this is the new bit

g.DrawLine(mypen, 5, 5, 5, 95)

g.DrawLine(mypen, 5, 5, 95, 5)

g.DrawLine(mypen, 5, 5, 95, 95)

g.DrawLine(mypen, 5, 5, 95, 20)

g.DrawLine(mypen, 5, 5, 95, 20)

g.DrawLine(mypen, 5, 5, 95, 40)

g.DrawLine(mypen, 5, 5, 95, 60)



....and now it works the way I want it to. I gather similar schenanigans are
required to deal with text.



It sure would be a lot more convenient if you had some control on what the
transformations applied to.

While I can understand why someone might want it to work the way it does,
for the sorts of things

I do (drawing charts), I want translations and scaling to apply when
determining where

things go, but not to line widths, or how text appears (unless I want it to,
like rotating an axis label).

In the end, I'll probably end up burying all the details in a subroutine
library, so I mainly have to

decide whether to figure out how to invert the transformations as needed, or
whether to ditch them

altogether, and just do the linear transformations myself.







"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:eJVioF2tEHA.224@TK2MSFTNGP15.phx.gbl...
> You could try to set up the matrix for the pen scaling like this...
>
> Dim mx as new Matrix(1.0f/xscale,0,0,1.0f/yscale,0,0)
> myPen.Transorm=mx
>
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/gdipl...
>
> The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
> Bob's Blog: http://bobpowelldotnet.blogspot.co...
>
>
>
>
>
>
> "James Parsly" <japarsly@nospam.tva.gov> wrote in message
> news:newscache$wf8w5i$hp7$1@lyris.knx.tva.gov...
> > In this second case, what happens if your transformation is different in
> the
> > X and Y directions?
> >
> > Suppose you do something like this:
> >
> > Dim g As Graphics = e.Graphics
> >
> > Dim mypen As New Pen(Color.Red, 2) 'lets be difficult and ask for a
> thicker
> > line
> >
> > g.ScaleTransform(1, 5)
> >
> > g.DrawLine(mypen, 5, 5, 5, 95)
> >
> > g.DrawLine(mypen, 5, 5, 95, 5)
> >
> > g.DrawLine(mypen, 5, 5, 95, 95)
> >
> > g.DrawLine(mypen, 5, 5, 95, 20)
> >
> > g.DrawLine(mypen, 5, 5, 95, 20)
> >
> > g.DrawLine(mypen, 5, 5, 95, 40)
> >
> > g.DrawLine(mypen, 5, 5, 95, 60)
> >
> > This produces lines whose width varies depending on what direction they
> >
> > are drawn. How would you make them all come out the same width?
> >
> > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> > news:%23sgA8yqtEHA.2624@TK2MSFTNGP11.phx.gbl...
> > > There are two ways to do this.
> > >
> > > First, create pens with a width of -1. Any pen created in this way
> should
> > > provide a 1 pixel thick line regardless of the page scale settings.
> > >
> > > Second, if you must use a line that isn't 1 pixel, scale the pen to be
> the
> > > reciprocal of the page scale ie pen-scale = 1/page scale.
> > >
> > > Hope this helps.
> > >
> > > --
> > > Bob Powell [MVP]
> > > Visual C#, System.Drawing
> > >
> > > Answer those GDI+ questions with the GDI+ FAQ
> > > http://www.bobpowell.net/gdipl...
> > >
> > > The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> > > Windows Forms Tips and Tricks RSS:
> http://www.bobpowell.net/tips...
> > > Bob's Blog: http://bobpowelldotnet.blogspot.co...
> > >
> > >
> > >
> > >
> > >
> > >
> > > "Arkion" <nospam@nowhere.com> wrote in message
> > > news:d0qcn01ovp5kvgm3c3dhbq26ao9vb3pumn@4ax.com...
> > > > Hi all!
> > > > I'm using ScaleTransform to implement zoom in/out functionality. I'd
> > > > like to have the ScaleTransform only affect the positioning of
> > > > endpoints of lines drawn using Graphics.DrawLine, ie. the thickness
of
> > > > lines should stay constant. Is this possible?
> > >
> > >
> >
> >
>
>


Bob Powell

10/21/2004 2:20:00 PM

0

Ahh charts.. I designed Stingray Objetive Chart so I feel your pain.

There is an article in the GDI+ FAQ explaining how to display text the right
way up on a reversed axis.

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

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tips...
Bob's Blog: http://bobpowelldotnet.blogspot.co...






"James Parsly" <japarsly@nospam.tva.gov> wrote in message
news:newscache$rfxx5i$5x9$1@lyris.knx.tva.gov...
> From this hint, I changed the code as follows:
>
> Dim g As Graphics = e.Graphics
>
> Dim mypen As New Pen(Color.Red, 2)
>
> g.ScaleTransform(2, 5)
>
> mypen.ScaleTransform(0.5F, 0.2F) '<---- this is the new bit
>
> g.DrawLine(mypen, 5, 5, 5, 95)
>
> g.DrawLine(mypen, 5, 5, 95, 5)
>
> g.DrawLine(mypen, 5, 5, 95, 95)
>
> g.DrawLine(mypen, 5, 5, 95, 20)
>
> g.DrawLine(mypen, 5, 5, 95, 20)
>
> g.DrawLine(mypen, 5, 5, 95, 40)
>
> g.DrawLine(mypen, 5, 5, 95, 60)
>
>
>
> ...and now it works the way I want it to. I gather similar schenanigans
are
> required to deal with text.
>
>
>
> It sure would be a lot more convenient if you had some control on what the
> transformations applied to.
>
> While I can understand why someone might want it to work the way it does,
> for the sorts of things
>
> I do (drawing charts), I want translations and scaling to apply when
> determining where
>
> things go, but not to line widths, or how text appears (unless I want it
to,
> like rotating an axis label).
>
> In the end, I'll probably end up burying all the details in a subroutine
> library, so I mainly have to
>
> decide whether to figure out how to invert the transformations as needed,
or
> whether to ditch them
>
> altogether, and just do the linear transformations myself.
>
>
>
>
>
>
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:eJVioF2tEHA.224@TK2MSFTNGP15.phx.gbl...
> > You could try to set up the matrix for the pen scaling like this...
> >
> > Dim mx as new Matrix(1.0f/xscale,0,0,1.0f/yscale,0,0)
> > myPen.Transorm=mx
> >
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/gdipl...
> >
> > The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> > Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tips...
> > Bob's Blog: http://bobpowelldotnet.blogspot.co...
> >
> >
> >
> >
> >
> >
> > "James Parsly" <japarsly@nospam.tva.gov> wrote in message
> > news:newscache$wf8w5i$hp7$1@lyris.knx.tva.gov...
> > > In this second case, what happens if your transformation is different
in
> > the
> > > X and Y directions?
> > >
> > > Suppose you do something like this:
> > >
> > > Dim g As Graphics = e.Graphics
> > >
> > > Dim mypen As New Pen(Color.Red, 2) 'lets be difficult and ask for a
> > thicker
> > > line
> > >
> > > g.ScaleTransform(1, 5)
> > >
> > > g.DrawLine(mypen, 5, 5, 5, 95)
> > >
> > > g.DrawLine(mypen, 5, 5, 95, 5)
> > >
> > > g.DrawLine(mypen, 5, 5, 95, 95)
> > >
> > > g.DrawLine(mypen, 5, 5, 95, 20)
> > >
> > > g.DrawLine(mypen, 5, 5, 95, 20)
> > >
> > > g.DrawLine(mypen, 5, 5, 95, 40)
> > >
> > > g.DrawLine(mypen, 5, 5, 95, 60)
> > >
> > > This produces lines whose width varies depending on what direction
they
> > >
> > > are drawn. How would you make them all come out the same width?
> > >
> > > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> > > news:%23sgA8yqtEHA.2624@TK2MSFTNGP11.phx.gbl...
> > > > There are two ways to do this.
> > > >
> > > > First, create pens with a width of -1. Any pen created in this way
> > should
> > > > provide a 1 pixel thick line regardless of the page scale settings.
> > > >
> > > > Second, if you must use a line that isn't 1 pixel, scale the pen to
be
> > the
> > > > reciprocal of the page scale ie pen-scale = 1/page scale.
> > > >
> > > > Hope this helps.
> > > >
> > > > --
> > > > Bob Powell [MVP]
> > > > Visual C#, System.Drawing
> > > >
> > > > Answer those GDI+ questions with the GDI+ FAQ
> > > > http://www.bobpowell.net/gdipl...
> > > >
> > > > The GDI+ FAQ RSS feed: http://www.bobpowell.net/f...
> > > > Windows Forms Tips and Tricks RSS:
> > http://www.bobpowell.net/tips...
> > > > Bob's Blog: http://bobpowelldotnet.blogspot.co...
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > "Arkion" <nospam@nowhere.com> wrote in message
> > > > news:d0qcn01ovp5kvgm3c3dhbq26ao9vb3pumn@4ax.com...
> > > > > Hi all!
> > > > > I'm using ScaleTransform to implement zoom in/out functionality.
I'd
> > > > > like to have the ScaleTransform only affect the positioning of
> > > > > endpoints of lines drawn using Graphics.DrawLine, ie. the
thickness
> of
> > > > > lines should stay constant. Is this possible?
> > > >
> > > >
> > >
> > >
> >
> >
>
>