Questions, comments and suggestions concerning VintaSoft Annotation .NET Plug-in.
Moderator: Alex
iansml
Posts: 31 Joined: Thu Apr 23, 2009 1:57 pm
Post
by iansml » Fri Apr 24, 2009 5:58 pm
Hi,
I have an image with couple of annotations on it (not merged). I want to be able to rotate the image AND annotations together (keeping same relative position) without merging them.
When I rotate the image using:
Code: Select all
imageViewer1.FocusedImage.Rotate(90);
- the image rotates but the annotations stay where they are.
I tried rotating the image AND annotation using the following:
Code: Select all
imageViewer1.FocusedImage.Rotate(90);
foreach (AnnotationBase ab in imageViewer1.Annotations.SelectedCollection)
{
ab.Rotation = 90;
}
- which does rotate the annotation, but does not leave it in the same relative position on the image.
I haven't found anything in the example code that helps. Any ideas..?
Alex
Site Admin
Posts: 2397 Joined: Thu Jul 10, 2008 2:21 pm
Post
by Alex » Mon Apr 27, 2009 1:35 pm
Hi Ian,
Thank you for good question. Here is correct code for 90 degree rotation:
Code: Select all
VintasoftImage vsImage = annotationViewer1.Images[0];
int imageWidth = vsImage.Width;
int imageHeight = vsImage.Height;
vsImage.Rotate(90);
foreach (AnnotationBase ab in annotationViewer1.Annotations.SelectedCollection)
{
PointF oldLocation = ab.Location;
PointF newLocation = new PointF(imageHeight - oldLocation.Y, oldLocation.X);
ab.Location = newLocation;
ab.Rotation = 90;
}
Formulas for rotations to 180 and 270 degrees can be calculated in the same way.
We will add ability to rotate image with annotations to the any angle in next version of library.
Best regards, Alexander
iansml
Posts: 31 Joined: Thu Apr 23, 2009 1:57 pm
Post
by iansml » Mon Apr 27, 2009 5:34 pm
OK, thanks very much. That seems to work fine.
iansml
Posts: 31 Joined: Thu Apr 23, 2009 1:57 pm
Post
by iansml » Fri May 08, 2009 1:11 pm
Hi Alex,
I didn't realise that this works for a right rotation (90) only. It does not work for left rotations (-90), 180 or a number of other custom ones. In these cases the annotations end up going all over the place. Do you have any code that will suit all possible positive and negative rotation angles?
Please note that some of these problems only occur when you rotate multiple times - e.g. 3x click on a rotate left button.
When will the library with this fix be released?
Thanks.
Alex
Site Admin
Posts: 2397 Joined: Thu Jul 10, 2008 2:21 pm
Post
by Alex » Fri May 08, 2009 1:35 pm
Hi Ian,
Here is updated code:
Code: Select all
int prevRotationAngle = 0;
private void RotateImageWithAnno(int rotationAngle)
{
while (rotationAngle > 360) rotationAngle -= 360;
while (rotationAngle < 0) rotationAngle += 360;
if ((rotationAngle % 90) != 0) return;
VintasoftImage vsImage = annotationViewer1.Images[0];
int imageWidth = vsImage.Width;
int imageHeight = vsImage.Height;
vsImage.Rotate(rotationAngle);
foreach (AnnotationBase ab in annotationViewer1.Annotations.SelectedCollection)
{
PointF oldLocation = ab.Location;
PointF newLocation = oldLocation;
switch (rotationAngle)
{
case 90:
newLocation = new PointF(imageHeight - oldLocation.Y, oldLocation.X);
break;
case 180:
newLocation = new PointF(imageWidth - oldLocation.X, imageHeight - oldLocation.Y);
break;
case 270:
newLocation = new PointF(oldLocation.Y, imageWidth - oldLocation.X);
break;
}
ab.Location = newLocation;
ab.Rotation = rotationAngle + prevRotationAngle;
}
prevRotationAngle += rotationAngle;
}
private void buttonRotate90_Click(object sender, EventArgs e)
{
RotateImageWithAnno(90);
}
private void buttonRotate270_Click(object sender, EventArgs e)
{
RotateImageWithAnno(-90);
}
Best regards, Alexander
iansml
Posts: 31 Joined: Thu Apr 23, 2009 1:57 pm
Post
by iansml » Fri May 08, 2009 1:43 pm
Hi Alex,
Thanks for quick reply. Looking at the code this still works only for increments of +/- 90 degrees. I currently provide an option for users to rotate images by a custom amount (e.g. 37, -176). This code will still not work in these cases. Do you have code that will work for these custom values? If not, will it be available in the next control version?
Thanks, Ian
Alex
Site Admin
Posts: 2397 Joined: Thu Jul 10, 2008 2:21 pm
Post
by Alex » Fri May 08, 2009 1:46 pm
Rotation of image with annotation to custom angle will be available in next version of library, I think in 1-2 weeks.
Best regards, Alexander