Page 1 of 1

Rotating annotations

Posted: Fri Apr 24, 2009 5:58 pm
by iansml
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..?

Re: Rotating annotations

Posted: Mon Apr 27, 2009 1:35 pm
by Alex
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

Re: Rotating annotations

Posted: Mon Apr 27, 2009 5:34 pm
by iansml
OK, thanks very much. That seems to work fine.

Re: Rotating annotations

Posted: Fri May 08, 2009 1:11 pm
by iansml
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.

Re: Rotating annotations

Posted: Fri May 08, 2009 1:35 pm
by Alex
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

Re: Rotating annotations

Posted: Fri May 08, 2009 1:43 pm
by iansml
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

Re: Rotating annotations

Posted: Fri May 08, 2009 1:46 pm
by Alex
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