mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
Fixed rotation formula
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1679 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
a5295fb5a4
commit
25f8d81d5a
1 changed files with 30 additions and 20 deletions
|
@ -571,35 +571,45 @@ namespace Greenshot.Drawing {
|
||||||
case Effects.Grayscale:
|
case Effects.Grayscale:
|
||||||
newImage = ImageHelper.CreateGrayscale((Bitmap)Image);
|
newImage = ImageHelper.CreateGrayscale((Bitmap)Image);
|
||||||
break;
|
break;
|
||||||
case Effects.Rotate270:
|
case Effects.Rotate90:
|
||||||
MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false);
|
MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false);
|
||||||
foreach(DrawableContainer drawableContainer in elements) {
|
foreach(DrawableContainer drawableContainer in elements) {
|
||||||
int x1 = drawableContainer.Bounds.X - (Width >> 1);
|
int angle = 270;
|
||||||
int y1 = (-drawableContainer.Bounds.Y) + (Height >> 1);
|
int ox = 0;
|
||||||
int rotatedX1 = y1;
|
int oy = 0;
|
||||||
int rotatedY1 = -x1;
|
int centerX = Width>>1;
|
||||||
int newX1 = y1 + (Height >> 1);
|
int centerY = Height>>1;
|
||||||
int newY1 = -x1 - (Width >> 1);
|
int px = drawableContainer.Bounds.X - centerX;
|
||||||
|
int py = centerY - drawableContainer.Bounds.Y;
|
||||||
|
double theta = Math.PI * angle / 180.0;
|
||||||
|
double x1 = Math.Cos(theta) * (px-ox) - Math.Sin(theta) * (py-oy) + ox;
|
||||||
|
double y1 = Math.Sin(theta) * (px-ox) + Math.Cos(theta) * (py-oy) + oy;
|
||||||
|
|
||||||
int x2 = (drawableContainer.Bounds.X+drawableContainer.Bounds.Width) - (Width >> 1);
|
// Transform to Cartesian coordinates
|
||||||
int y2 = (-(drawableContainer.Bounds.Y+drawableContainer.Bounds.Height)) + (Height >> 1);
|
px = (drawableContainer.Bounds.X+drawableContainer.Bounds.Width) - centerX;
|
||||||
int rotatedX2 = y2;
|
py = centerY - (drawableContainer.Bounds.Y+drawableContainer.Bounds.Height);
|
||||||
int rotatedY2 = -x2;
|
|
||||||
int newX2 = y2 + (Height >> 1);
|
double x2 = Math.Cos(theta) * (px-ox) - Math.Sin(theta) * (py-oy) + ox;
|
||||||
int newY2 = -x2 - (Width >> 1);
|
double y2 = Math.Sin(theta) * (px-ox) + Math.Cos(theta) * (py-oy) + oy;
|
||||||
int newWidth = newX2 - newX1;
|
x1 += centerY;
|
||||||
int newHeight = newY2 - newY1;
|
x2 += centerY;
|
||||||
|
y1 = centerX - y1;
|
||||||
|
y2 = centerX - y2;
|
||||||
|
|
||||||
|
// Calculate to rectangle
|
||||||
|
double newWidth = x2 - x1;
|
||||||
|
double newHeight = y2 - y1;
|
||||||
|
|
||||||
RectangleF newRectangle = new RectangleF(
|
RectangleF newRectangle = new RectangleF(
|
||||||
newX1,
|
(float)x1,
|
||||||
newY1,
|
(float)y1,
|
||||||
newWidth,
|
(float)newWidth,
|
||||||
newHeight
|
(float)newHeight
|
||||||
);
|
);
|
||||||
LOG.DebugFormat("Bounds before {0}, bounds after {1}", drawableContainer.Bounds, newRectangle);
|
LOG.DebugFormat("Bounds before {0}, bounds after {1}", drawableContainer.Bounds, newRectangle);
|
||||||
drawableContainer.ApplyBounds(newRectangle);
|
drawableContainer.ApplyBounds(newRectangle);
|
||||||
}
|
}
|
||||||
newImage = ImageHelper.RotateFlip((Bitmap)Image, RotateFlipType.Rotate270FlipNone);
|
newImage = ImageHelper.RotateFlip((Bitmap)Image, RotateFlipType.Rotate90FlipNone);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue