Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
erwinrichard  
#1 Posted : Wednesday, January 7, 2009 4:43:30 AM(UTC)
erwinrichard

Rank: Newbie

Groups: Member
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
Dmitry  
#2 Posted : Wednesday, January 7, 2009 3:19:01 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
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?
Sincerely yours,
Dmitry Sevostyanov

UserPostedImage Follow Aurigma on Twitter!
erwinrichard  
#3 Posted : Wednesday, January 7, 2009 10:41:54 PM(UTC)
erwinrichard

Rank: Newbie

Groups: Member
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
Alex Kon  
#4 Posted : Thursday, January 8, 2009 4:33:11 PM(UTC)
Alex Kon

Rank: Advanced Member

Groups:
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

erwinrichard  
#5 Posted : Sunday, January 11, 2009 11:12:01 PM(UTC)
erwinrichard

Rank: Newbie

Groups: Member
Joined: 1/6/2009(UTC)
Posts: 8

Thanks, Alex

works perfectly.

Regards Erwin
Users browsing this topic
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.