Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw rotated rectangle

I'm new to C# and .net, just trying to work out how to do something that I thought would be relatively simple. I'm creating a bitmap to be later saved as an image to disk, part of it I want to draw a rectangle shape. I can do this, however I'm looking for a simple way to do this on an angle. I need to be able to specify an angle to draw the rectangle at, I also need to be able to to specify the rotation point (I need to rotate around the top left hand point of the rectangle).

How is this usually achieved with c#/.net, is there something built in for this sort of thing that I haven't found ?

like image 300
chip Avatar asked Sep 20 '25 01:09

chip


1 Answers

The Graphics class supports setting transforms that will let you scale, shear, rotate, etc. See Coordinate Systems and Transformations.

You can find an example at Using a matrix to rotate rectangles individually.

like image 198
Jim Mischel Avatar answered Sep 22 '25 15:09

Jim Mischel