Home : Annotations : Manipulating : Rotate Annotations Along With a Background Image on a Webform
Q10199 - HOWTO: Rotate Annotations Along With a Background Image on a Webform

For each annotation you need to:

1. recalculate the new upper left X,Y Value

2. rotate the annotation and

3. move the annotation to the new position.

 

Server Side

[C#]

[RemoteInvokable]
public void RotateEverything(int degs)
{
 
    foreach (AnnotationUI anno in WebImageViewer1.Annotations.CurrentLayer.Items)
    {

 //Move it
 if (degs == 90)
 {
     float newX =(float)(WebImageViewer1.Image.Height) - anno.Location.Y;
     float newY = anno.Location.X;
     anno.Rotate(90);
     anno.Location = new PointF(newX, newY);
 }
 else if (degs == -90)
 {
     float newX = anno.Location.Y;
     float newY = (float)(WebImageViewer1.Image.Width) - anno.Location.X;
     anno.Rotate(-90);
     anno.Location = new PointF(newX, newY);
 }
 else if (degs == 180)
 {
     float newX = (float)(WebImageViewer1.Image.Width) - anno.Location.X;
     float newY = (float)(WebImageViewer1.Image.Height) - anno.Location.Y;
     anno.Rotate(180);
     anno.Location = new PointF(newX, newY);
 }
    }
  

    this.WebImageViewer1.UpdateAnnotations();
    this.WebImageViewer1.ApplyCommand(new RotateCommand(degs));
    this.WebImageViewer1.Image.Save(@"C:\Tempfile.jpg", new JpegEncoder(), null);

}

[VB]

<RemoteInvokable()> _
Public Sub RotateEverything(ByVal degs As Integer)
  
    For Each anno As AnnotationUI In WebImageViewer1.Annotations.CurrentLayer.Items       
        'Move it
        If degs = 90 Then
            Dim newX As Single = CSng(DirectCast(-anno.Location.Y, WebImageViewer1.Image.Height))
            Dim newY As Single = anno.Location.X
            anno.Rotate(90)
            anno.Location = New PointF(newX, newY)
ElseIf degs = -90 Then
            Dim newX As Single = anno.Location.Y
            Dim newY As Single = CSng(DirectCast(-anno.Location.X, WebImageViewer1.Image.Width))
            anno.Rotate(-90)
            anno.Location = New PointF(newX, newY)
ElseIf degs = 180 Then
            Dim newX As Single = CSng(DirectCast(-anno.Location.X, WebImageViewer1.Image.Width))
            Dim newY As Single = CSng(DirectCast(-anno.Location.Y, WebImageViewer1.Image.Height))
            anno.Rotate(180)
            anno.Location = New PointF(newX, newY)
        End If
    Next
   
    Me.WebImageViewer1.UpdateAnnotations()
    Me.WebImageViewer1.ApplyCommand(New RotateCommand(degs))
    Me.WebImageViewer1.Image.Save("C:\Tempfile.jpg", New JpegEncoder(), Nothing)
  
End Sub

Client Side

<script type="text/javascript">
function Rotate(i) {
 var a = new Array();
 a.push(i);
 WebImageViewer1.RemoteInvoked = Invalidate;
 WebImageViewer1.RemoteInvoke('RotateEverything', a);
}
</script>

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved