【发布时间】:2011-08-25 21:03:54
【问题描述】:
我有一个位图,上面绘制了一个 Rectangle 对象。我希望能够 RotateFlip 位图并调整 Rectangle 的 x、y、宽度和高度,使其在每次旋转或翻转后与位图对齐。
例如,如果我有一个 1000 x 800 像素的位图,我可能会在其上绘制一个具有指定点和大小的 Rectangle 对象。
示例代码:
// A bitmap that's 1000x800 size
Bitmap bitmap = new Bitmap(fileName);
// Any arbitrary rectangle that can be drawn inside the bitmap boundaries
Rectangle rect = new Rectangle(200, 200, 100, 100);
bitmap.RotateFlip(rotateFlipType);
switch (rotateFlipType)
{
case Rotate90FlipNone:
// Adjust rectangle to match new bitmap orientation
rect = new Rectangle(?, ?, ?, ?);
break;
case RotateNoneFlip180:
rect = new Rectangle(?, ?, ?, ?);
break;
// ... etc.
}
【问题讨论】:
-
实际代码会增加混乱,但基本目的可以通过通用代码传达。我会把它添加到原始帖子中。
-
您是仅使用 90 度增量还是需要任意度数?您是围绕矩形的中心点还是其中一个角旋转?与翻转、中心点或边缘相同?
标签: c# bitmap rotation degrees