mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 09:33:46 -07:00
Fixed rotate, also working on the BitmapContainer
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1680 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
25f8d81d5a
commit
0bb7f87ee5
3 changed files with 62 additions and 38 deletions
|
@ -100,7 +100,16 @@ namespace Greenshot.Drawing {
|
||||||
LOG.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
LOG.Debug("Loaded file: " + filename + " with resolution: " + Height + "," + Width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Rotate(RotateFlipType rotateFlipType) {
|
||||||
|
Bitmap newBitmap = ImageHelper.RotateFlip((Bitmap)bitmap, rotateFlipType);
|
||||||
|
if (bitmap != null) {
|
||||||
|
bitmap.Dispose();
|
||||||
|
}
|
||||||
|
bitmap = newBitmap;
|
||||||
|
base.Rotate(rotateFlipType);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(Graphics graphics, RenderMode rm) {
|
public override void Draw(Graphics graphics, RenderMode rm) {
|
||||||
if (bitmap != null) {
|
if (bitmap != null) {
|
||||||
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
|
||||||
|
|
|
@ -590,7 +590,50 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void Rotate(RotateFlipType rotateFlipType) {
|
||||||
|
// somehow the rotation is the wrong way?
|
||||||
|
int angle = 90;
|
||||||
|
if (RotateFlipType.Rotate90FlipNone == rotateFlipType) {
|
||||||
|
angle = 270;
|
||||||
|
}
|
||||||
|
int ox = 0;
|
||||||
|
int oy = 0;
|
||||||
|
int centerX = parent.Width >> 1;
|
||||||
|
int centerY = parent.Height >> 1;
|
||||||
|
// Transform from screen to normal coordinates
|
||||||
|
int px = Left - centerX;
|
||||||
|
int py = centerY - Top;
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Transform from screen to normal coordinates
|
||||||
|
px = (Left + Width) - centerX;
|
||||||
|
py = centerY - (Top + Height);
|
||||||
|
|
||||||
|
double x2 = Math.Cos(theta) * (px - ox) - Math.Sin(theta) * (py - oy) + ox;
|
||||||
|
double y2 = Math.Sin(theta) * (px - ox) + Math.Cos(theta) * (py - oy) + oy;
|
||||||
|
|
||||||
|
// Transform back to screen coordinates, as we rotate the bitmap we need to switch the center X&Y
|
||||||
|
x1 += centerY;
|
||||||
|
y1 = centerX - y1;
|
||||||
|
x2 += centerY;
|
||||||
|
y2 = centerX - y2;
|
||||||
|
|
||||||
|
// Calculate to rectangle
|
||||||
|
double newWidth = x2 - x1;
|
||||||
|
double newHeight = y2 - y1;
|
||||||
|
|
||||||
|
RectangleF newRectangle = new RectangleF(
|
||||||
|
(float)x1,
|
||||||
|
(float)y1,
|
||||||
|
(float)newWidth,
|
||||||
|
(float)newHeight
|
||||||
|
);
|
||||||
|
ApplyBounds(newRectangle);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() {
|
protected virtual ScaleHelper.IDoubleProcessor GetAngleRoundProcessor() {
|
||||||
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -572,44 +572,16 @@ namespace Greenshot.Drawing {
|
||||||
newImage = ImageHelper.CreateGrayscale((Bitmap)Image);
|
newImage = ImageHelper.CreateGrayscale((Bitmap)Image);
|
||||||
break;
|
break;
|
||||||
case Effects.Rotate90:
|
case Effects.Rotate90:
|
||||||
|
case Effects.Rotate270:
|
||||||
MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false);
|
MakeUndoable(new DrawableContainerBoundsChangeMemento(elements.AsIDrawableContainerList()), false);
|
||||||
foreach(DrawableContainer drawableContainer in elements) {
|
RotateFlipType rotateFlipType = RotateFlipType.Rotate270FlipNone;
|
||||||
int angle = 270;
|
if (effect == Effects.Rotate90) {
|
||||||
int ox = 0;
|
rotateFlipType = RotateFlipType.Rotate90FlipNone;
|
||||||
int oy = 0;
|
|
||||||
int centerX = Width>>1;
|
|
||||||
int centerY = Height>>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;
|
|
||||||
|
|
||||||
// Transform to Cartesian coordinates
|
|
||||||
px = (drawableContainer.Bounds.X+drawableContainer.Bounds.Width) - centerX;
|
|
||||||
py = centerY - (drawableContainer.Bounds.Y+drawableContainer.Bounds.Height);
|
|
||||||
|
|
||||||
double x2 = Math.Cos(theta) * (px-ox) - Math.Sin(theta) * (py-oy) + ox;
|
|
||||||
double y2 = Math.Sin(theta) * (px-ox) + Math.Cos(theta) * (py-oy) + oy;
|
|
||||||
x1 += centerY;
|
|
||||||
x2 += centerY;
|
|
||||||
y1 = centerX - y1;
|
|
||||||
y2 = centerX - y2;
|
|
||||||
|
|
||||||
// Calculate to rectangle
|
|
||||||
double newWidth = x2 - x1;
|
|
||||||
double newHeight = y2 - y1;
|
|
||||||
|
|
||||||
RectangleF newRectangle = new RectangleF(
|
|
||||||
(float)x1,
|
|
||||||
(float)y1,
|
|
||||||
(float)newWidth,
|
|
||||||
(float)newHeight
|
|
||||||
);
|
|
||||||
LOG.DebugFormat("Bounds before {0}, bounds after {1}", drawableContainer.Bounds, newRectangle);
|
|
||||||
drawableContainer.ApplyBounds(newRectangle);
|
|
||||||
}
|
}
|
||||||
newImage = ImageHelper.RotateFlip((Bitmap)Image, RotateFlipType.Rotate90FlipNone);
|
foreach (DrawableContainer drawableContainer in elements) {
|
||||||
|
drawableContainer.Rotate(rotateFlipType);
|
||||||
|
}
|
||||||
|
newImage = ImageHelper.RotateFlip((Bitmap)Image, rotateFlipType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue