Rank: Newbie
Groups: Guest
Joined: 1/6/2009(UTC) Posts: 8
|
Hi,
If I rotate a zoomed (Rubberband Zoom) image in the bitmap viewer, I would like the center of the zoomed area to stay in the center of the viewer.
Very new to the components, so can you please give me a clue?
Regards Erwin
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 8/3/2003(UTC) Posts: 1,070
Thanks: 1 times Was thanked: 12 time(s) in 12 post(s)
|
Hello Erwin,
How do you rotate an image? Could you give me code sample? |
|
|
|
|
Rank: Newbie
Groups: Guest
Joined: 1/6/2009(UTC) Posts: 8
|
I use code like this to rotate the image
private void rotateClockwiseButton_Click(object sender, EventArgs e) { using (WaitCursor wait = new WaitCursor()) { bitmapViewer1.Bitmap.Transforms.RotateAndFlip(System.Drawing.RotateFlipType.Rotate90FlipNone); //bitmapViewer1.Bitmap.Transforms.Rotate(90); } }
Now when the user has zoomed in and then rotates, I would like the center of the visible part of the image to be roughly the same as before rotation. This is for an application, where the user has to zoom in on certain parts of a picture and then recognise photographed labels which might be upside down or anther orientation than the image as a whole.
Maybe I should rotate the view, not the bitmap - but how to achieve this?
Reards Erwin
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 1/31/2005(UTC) Posts: 458
Was thanked: 5 time(s) in 5 post(s)
|
Hello, You should just correct scroll position of the BitmapViewer to place the same point of the image to the center of the control. Here is code sample: ("_bv" is BitmapViewer instance): Code:private void _rotateButton_Click(object sender, EventArgs e)
{
RotateFlipType angle = System.Drawing.RotateFlipType.Rotate270FlipNone;
Point controlCenter = new Point(_bv.Width / 2, _bv.Height / 2);
PointF workspaceCenter = _bv.ControlToWorkspace(
controlCenter,
Aurigma.GraphicsMill.Unit.Pixel);
workspaceCenter = RotatePoint(workspaceCenter, angle, _bv.WorkspaceWidth, _bv.WorkspaceHeight);
_bv.Bitmap.Transforms.RotateAndFlip(angle);
PointF newWorkspaceCenter = _bv.ControlToWorkspace(
controlCenter,
Aurigma.GraphicsMill.Unit.Pixel);
PointF shiftInWorkspace = new PointF(
workspaceCenter.X - newWorkspaceCenter.X,
workspaceCenter.Y - newWorkspaceCenter.Y);
Rectangle shiftInControl = _bv.WorkspaceToControl(
new RectangleF(0, 0, shiftInWorkspace.X, shiftInWorkspace.Y),
Aurigma.GraphicsMill.Unit.Pixel);
_bv.Scroll(shiftInControl.Width, shiftInControl.Height);
}
private PointF RotatePoint(
PointF pnt,
RotateFlipType angle,
float workspaceWidth,
float workspaceHeight)
{
PointF result;
switch (angle)
{
case RotateFlipType.Rotate90FlipNone:
result = new PointF(workspaceHeight - pnt.Y - 1, pnt.X);
break;
case RotateFlipType.Rotate180FlipNone:
result = new PointF(workspaceWidth - pnt.X - 1, workspaceHeight - pnt.Y - 1);
break;
case RotateFlipType.Rotate270FlipNone:
result = new PointF(pnt.Y, workspaceWidth - pnt.X - 1);
break;
default:
throw new ApplicationException("Unexpected angle has been specified.");
}
return result;
}
Edited by user Thursday, January 8, 2009 4:35:34 PM(UTC)
| Reason: Not specified |
|
|
|
|
Rank: Newbie
Groups: Guest
Joined: 1/6/2009(UTC) Posts: 8
|
Thanks, Alex
works perfectly.
Regards Erwin
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.