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

Notification

Icon
Error

Options
Go to last post Go to first unread
Tamila  
#1 Posted : Monday, September 22, 2008 5:59:29 PM(UTC)
Tamila

Rank: Advanced Member

Groups:
Joined: 3/9/2008(UTC)
Posts: 554

Was thanked: 1 time(s) in 1 post(s)
Overview

Suppose you use BitmapViewer control along with VobjectRubberband attached to it in your application to display an image and some overlaid vector objects. The users can edit these objects interactively: for example, move and resize them. After you finished this functionality you got a task to rotate the image and vector objects over it at 90 degrees.

If you try to rotate the image loaded into BitmapViewer using Rotate method, vector objects are not rotated automatically.

Resolution

To rotate vector objects after the image is rotated you need to get each of them and perform the rotation by-hand. The rotation should be done around the center of image loaded into BitmapViewer.

As you know each vector object has matrix that describes all transformations applied to this object. In terms of algebra to rotate an object around some point you should add two operations to this matrix:

  1. Translate origin of coordinates to the specified point.

  2. Rotate the object.

The following code sample demonstrates how to perform these operations:

Code:

Private Sub Form1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
  BitmapViewer1.Rubberband = VObjectsRubberband1
  BitmapViewer1.Bitmap.Load("c:\1.tif")
End Sub

Private Sub AddText_Click(ByVal sender As System.Object, ByVal e As _
  System.EventArgs) Handles Button1.Click
  Dim recF As New RectangleF(0, 0, 100, 100)
  Dim ff As New Aurigma.GraphicsMill.WinControls.TextVObject("Hello", _
  "Tahoma", 20, recF)
  VObjectsRubberband1.CurrentLayer.VObjects.Add(ff)
End Sub

Private Sub AddRectangle_Click(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button2.Click
  Dim recF As New RectangleF(250, 250, 150, 150)
  Dim ff As New Aurigma.GraphicsMill.WinControls.RectangleVObject(recF)
  ff.Brush = Brushes.Blue
  VObjectsRubberband1.CurrentLayer.VObjects.Add(ff)
End Sub

Private Sub Rotate_Click(ByVal sender As System.Object, ByVal e As _
  System.EventArgs) Handles Button3.Click 
  Dim w, h As Single

  If BitmapViewer1.ScaleToActualSize Then
     w = BitmapViewer1.WorkspaceWidth
     h = BitmapViewer1.WorkspaceHeight
  Else
     w = Aurigma.GraphicsMill.UnitConverter.ConvertPixelsToUnits(96.0, _
        BitmapViewer1.Bitmap.Width, Aurigma.GraphicsMill.Unit.Point)
     h = Aurigma.GraphicsMill.UnitConverter.ConvertPixelsToUnits(96.0, _
        BitmapViewer1.Bitmap.Height, Aurigma.GraphicsMill.Unit.Point)
  End If

  Dim i As Integer
  For i = 0 To VObjectsRubberband1.CurrentLayer.VObjects.Count - 1
     VObjectsRubberband1.CurrentLayer.VObjects.Item(i).Transform. _
       RotateAt(90, New PointF(w/2, h/2), Drawing2D.MatrixOrder.Append)
     VObjectsRubberband1.CurrentLayer.VObjects.Item(i).Update()
  Next

  BitmapViewer1.Bitmap.Transforms.Rotate(90)

  For i = 0 To VObjectsRubberband1.CurrentLayer.VObjects.Count - 1
    VObjectsRubberband1.CurrentLayer.VObjects.Item(i).Transform. _
      Translate((h - w) / 2, (w - h) / 2, Drawing2D.MatrixOrder.Append)
    VObjectsRubberband1.CurrentLayer.VObjects.Item(i).Update()
  Next

End Sub

Edited by user Saturday, October 4, 2008 6:15:53 PM(UTC)  | Reason: Not specified

Aurigma Support Team

UserPostedImage Follow Aurigma on Twitter!

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