Search

Atalasoft Knowledge Base

HOWTO: Rotate Annotations Along With a Background Image on a WebAnnotationViewer (Legacy Web Controls)

Administrator
DotImage

Legacy Controls NOTICE

This article references our legacy Web Forms Web Viewing controls (WebImageViewer, WebAnnotationViewer, WebThumbnailViewer). It is preserved for archival purposes, but support strongly recommends using our modern HTML5 web controls: WebDocumentViewer, WebDocumentThumbnailer instead)

INFO: WebDocumentViewer Whitepaper - Getting Started With Web Viewing

Main Article Content

For each annotation you need to:

  • recalculate the new upper left X,Y Value
  • rotate the annotation
  • 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.NET

 _
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

JavaScript

function Rotate(i) {
 var a = new Array();
 a.push(i);
 WebImageViewer1.RemoteInvoked = Invalidate;
 WebImageViewer1.RemoteInvoke('RotateEverything', a);
}

Original Article:
Q10199 - HOWTO: Rotate Annotations Along With a Background Image on a WebAnnotationViewer (Legacy Web Controls)

Details
Last Modified: 6 Years Ago
Last Modified By: Administrator
Type: HOWTO
Rated 1 star based on 1 vote
Article has been viewed 618 times.
Options
Also In This Category