AppDev Posted November 18, 2011 Share Posted November 18, 2011 (edited) Hi, I am new to Paint.net Plugin development. I have viewed few tutorials to code in C# using CodeLab. I have write a simple program that draw an Arrow on the canvas using different parameters. The code for drawing arrow is as follow. Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); dst.CopySurface(src,rect.Location,rect); // create a Brush to draw a filled Polygon SolidBrush myBrushColor1 = new SolidBrush(Amount9); // create a GDI+ graphics surface Graphics g = new RenderArgs(dst).Graphics; g.Clip = new Region(rect); // Code for Drawing Arrow g.FillPolygon(myBrushColor1, new PointF[] { new PointF(Amount1, Amount2), new PointF(Amount1+Amount4, Amount2), new PointF(Amount1+Amount4, Amount2-Amount5), new PointF(Amount1+Amount4+Amount6, Amount2-Amount5), new PointF(Amount1, Amount2-Amount5-Amount8) }); By using the above code the Arrow is drawn on the canvas successfully. Now I want to rotate the Drawn arrow to any specified angle. I have used g.RotateTransform(Angle); but it rotate the arrow according to the starting point of the canvas, but i want to rotate the arrow around its center point. Any help will be appreciated. Thanks, Edited November 18, 2011 by AppDev Quote Link to comment Share on other sites More sharing options...
pyrochild Posted November 18, 2011 Share Posted November 18, 2011 g.TranslateTransform() Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
Rick Brewster Posted November 19, 2011 Share Posted November 19, 2011 Well, not translate per se. Probably RotateAt(). You may need to use stuff on Matrix and not just Graphics. In any case, you need to modify the transform on the Graphics object. It's simple, albeit obnoxious, matrix math. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
pyrochild Posted November 19, 2011 Share Posted November 19, 2011 Well, not translate per se. Probably RotateAt(). You may need to use stuff on Matrix and not just Graphics. In any case, you need to modify the transform on the Graphics object. It's simple, albeit obnoxious, matrix math. Not really necessary. TranslateTransform() will move the origin of the Graphics object, then RotateTransform() will rotate it about the new origin. Quote ambigram signature by Kemaru [i write plugins and stuff] If you like a post, upvote it! Link to comment Share on other sites More sharing options...
AppDev Posted November 19, 2011 Author Share Posted November 19, 2011 (edited) Thank you all for your replies. I have used g.TranslateTransform(p1, p2); and g.RotateTransform(angle); but it still not rotating the arrow around a specific point. I have attached the screenshots of the problem. I have drawn the arrow on point (400, 400). In the 1st screenshot I have set g.TranslateTransform(0, 0); and g.RotateTransform(0); and the arrow is positioned right where it is drawn with no rotation. i.e. (400,400). In the 2nd screenshot I have set g.TranslateTransform(0, 0); and g.RotateTransform(20); and the arrow is positioned Below the position (400, 400) with a little angle. In the 3rd screenshot I have set g.TranslateTransform(400, 400); and g.RotateTransform(20); and most of the arrow is positioned outside the canvas. Am I missing something here? What values I will use to correctly do this? Also When I declare an object of Matrix class it gives an error "The type or namespace "Matrix" could not be found" Edited November 19, 2011 by AppDev Quote Link to comment Share on other sites More sharing options...
AppDev Posted November 19, 2011 Author Share Posted November 19, 2011 Hi all, I have figured it out. I was actually drawing polygon at point (400,400) and then applying transform to it which was causing rotation problem. Now i have drawn the Polygon at Point (0,0) and applied TranslateTranform(400,400), now polygon is rotating around point (400, 400). Thanx all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.