Sign in to follow this  

[.net] [GDI+] Translating a Region

Recommended Posts

In the following code:
Point[] vertices = { Point(50, 100), new Point(100, 50), new Point(150, 100) };
GraphicsPath path = new GraphicsPath();
region = new Region(path);
Graphics g = CreateGraphics();

region.Translate(10, 0);
int x1 = (int)region.GetBounds(g).X;
//region = region.Clone();
region.Translate(20, 0);
int x2 = (int)region.GetBounds(g).X;

x1 is 60, and I would expect x2 to be 80. However, it's only 80 if I uncomment the call to Clone(). Otherwise it's 60, as if the second call to Translate() has no effect. EDIT: If I comment out the line that assigns x1, then x2 is 80 whether I call Clone() or not. It's as if calling GetBounds() somehow "fixes" the bounds so that you can't modify them anymore? Any idea what's causing this? Thanks in advance. [Edited by - Gage64 on May 3, 2010 1:26:38 PM]

Share this post

Link to post
Share on other sites

Try adding a GetHRGN call followed by a GetRgnBox call. With that you can get the GDI region's equivalent RECT and you may see (as I did) that RECT.left is 61 for your first call and RECT.left is 81 for the second call.

But the docs say that "The rectangle returned by Region::GetBounds is not always the smallest possible rectangle."

So technically, all it has to do is return any rect that contains the region in order to be considered functioning properly. :)

Share this post

Link to post
Share on other sites
Thanks, I'll give it a try.

But I still don't understand why the first call to GetBounds() affects the second call, and why cloning the region changes this behavior.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this