473,387 Members | 1,515 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,387 software developers and data experts.

GDI+ Transormations

Hi all!

A question about transformations.

Let's have this piece of code that transforms the coordinates of the
Graphics object:

---------
Graphics g = e.Graphics;
Matrix m = g.Transform;
m.RotateAt(45, new Point(100, 100));
g.Transform = m;
g.DrawRectangle(Pens.Blue, 50, 50, 100, 100);
---------

This works, ok.
But let's say that I need to get if a point falls into the transformed
rectangle, i.e.:

Rectangle r = new Rectangle(50, 50, 100, 100);
Console.Write(r.Contains(55, 55);

Obviously, this fails, since the point is computed with the "normal"
coordinates.
There is a way to transform also the coordinates of the control surface?

Thanks!

--

Free .Net Reporting Tool - http://www.neodatatype.net
May 3 '06 #1
3 1881
> A question about transformations.

Let's have this piece of code that transforms the coordinates of the
Graphics object:

---------
Graphics g = e.Graphics;
Matrix m = g.Transform;
m.RotateAt(45, new Point(100, 100));
g.Transform = m;
g.DrawRectangle(Pens.Blue, 50, 50, 100, 100);
---------

This works, ok.
But let's say that I need to get if a point falls into the transformed
rectangle, i.e.:

Rectangle r = new Rectangle(50, 50, 100, 100);
Console.Write(r.Contains(55, 55);

Obviously, this fails, since the point is computed with the "normal"
coordinates.
There is a way to transform also the coordinates of the control surface?


Bob Powell addresses this point in one of his excellent tutorials:

http://www.bobpowell.net/manipulate_graphics.htm
May 3 '06 #2
"Martijn Mulder" <i@m> ha scritto nel messaggio
news:44***********************@news.wanadoo.nl...

Bob Powell addresses this point in one of his excellent tutorials:

http://www.bobpowell.net/manipulate_graphics.htm


Wow, works great!

Thanks!

Jast a question: I don't understand why in this case I need to do a
Matrix.Invert() while it is not required when I draw on the Graphics.
May 3 '06 #3
Fabio,

Transformations are applied when you draw and they don't affect the data in
the Rectangle object.

I have two suuggestion:
1. Add the rectangle to a GraphicsPath, apply the transformation on the
graphics path (this will modify the coordinates inside the path) and now use
IsVisible or IsOutlineVisible GraphicsPath method to hit test.
2. Create a Matrix that does the oposite inversion (form trasnformed
coorinates to normal (not-trasnformed) and apply the trasnformation on the
the point you want to hittest against and then check with the rectangle.

Matrix m = new Matrix();
m.RotateAt(90, new Point(100, 100));
m.Invert();

Rectangle r = new Rectangle(50, 75, 100, 50);
Point[] pts = new Point[]{new Point(100,50)};
m.TransformPoints(pts);
Console.Write(r.Contains(pts[0]));
--
HTH
Stoitcho Goutsev (100)

"Fabio" <zn*******@virgilio.it> wrote in message
news:eK**************@TK2MSFTNGP03.phx.gbl...
Hi all!

A question about transformations.

Let's have this piece of code that transforms the coordinates of the
Graphics object:

---------
Graphics g = e.Graphics;
Matrix m = g.Transform;
m.RotateAt(45, new Point(100, 100));
g.Transform = m;
g.DrawRectangle(Pens.Blue, 50, 50, 100, 100);
---------

This works, ok.
But let's say that I need to get if a point falls into the transformed
rectangle, i.e.:

Rectangle r = new Rectangle(50, 50, 100, 100);
Console.Write(r.Contains(55, 55);

Obviously, this fails, since the point is computed with the "normal"
coordinates.
There is a way to transform also the coordinates of the control surface?

Thanks!

--

Free .Net Reporting Tool - http://www.neodatatype.net

May 3 '06 #4

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

Similar topics

10
by: **ham | last post by:
I know that's an old dirty issue; GDI+ almost -the slowest part of the framework - has bothered many developers using it in animations. Even in managed C++ the performance is awful. Now, any dude...
2
by: °Ë´óɽÈË | last post by:
Hi guys, As you know, we can call SetROP2 to set the current foreground mix mode in GDI. But I doesn't work in GDI+. The step is: GetDC --> SetROP2 -->Graphics.FromDC, then draw sth by graphics...
6
by: James dean | last post by:
I have heard that the video drivers in GDI+ are a big performance issue. But is this only an issue with something like Games Programming i think...is this wrong?. What about a drawing application...
1
by: James dean | last post by:
Could someone explain how this works. I think the graphics card is used to do blitting and drawing shapes like rectangles. How does it draw using the Graphics card on the PC and why is this feature...
6
by: James dean | last post by:
I want a good site that will show clearly how much more functionality GDI+ has. I cannot seem to find anything other than sites that list "some" of the new functionality that GDI+ offers. A...
7
by: | last post by:
We create VC++ programs that does some GDI drawing functionality. I discovered GDI+ and this seems to be a big step forward, and appears to be standard available in Windows XP and Windows Server...
0
by: Brian Keating | last post by:
hi there i've a test program that creates a treeview and destroys it over and over, i keep track of the gdi object count for the process and see if they are ok. However when i switch on...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
7
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"...
5
by: Jonathan Boivin | last post by:
Hi, I've got some problems with loading bills using a bill usercontrol I built. If I load all current bills in my test environment (156) everything is fine once, but repeating the operation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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...

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.