Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Monday, October 17, 2016 4:11:40 PM(UTC)

aida  
aida

Groups: Registered
Posts: 9


Is there a method to rotate an ellipse region?
Have also tried to create a temp image, rotate it and then combine the result. However can't figure out to combine the 'transparent' extra space due to rotation with original image.
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Tuesday, October 18, 2016 5:53:31 AM(UTC)

aida  
aida

Groups: Registered
Posts: 9


Have found a method to do what I need to do using .NET GDI+.

There is also a nice example of doing exactly what I was originally trying to in the draw example for CDLL.

Quick GDI+ example

' Using GDI+, create an elliptical region
Dim gdipRegion As Region
Using path As New GraphicsPath()
path.AddEllipse(100, 200, 400, 100)
Dim m As New Matrix
m.RotateAt(-45, New PointF(100, 200))
path.Transform(m)
gdipRegion = New Region(path)
End Using

' Create a RasterRegion from this region
Using region As RasterRegion = RasterRegionConverter.ConvertFromRegion(gdipRegion)
' Add this region to the image
image1.SetRegion(Nothing, region, RasterRegionCombineMode.Set)
End Using

gdipRegion.Dispose()

' Fill the image with a color
Dim cmd As New FillCommand(RasterColor.FromKnownColor(RasterKnownColor.Red))
cmd.Run(image1)
 
#3 Posted : Monday, October 31, 2016 10:39:54 AM(UTC)

Hadi  
Hadi

Groups: Manager, Tech Support, Administrators
Posts: 197

Was thanked: 9 time(s) in 9 post(s)

Thank you for following up your question with the solution that you found. This is the correct and easiest way to achieve what you are looking for.

Here is the code in a C#Code block for easier reading and formatting:

Code:
Region gdipRegion;

using (var path = new GraphicsPath())
{
   path.AddEllipse(100, 200, 400, 100);
   Matrix m = new Matrix();
   m.RotateAt(-45, new PointF(100, 200));
   path.Transform(m);
   gdipRegion = new Region(path);
}

using (RasterRegion region = RasterRegionConverter.ConvertFromRegion(gdipRegion))
   image1.SetRegion(null, region, RasterRegionCombineMode.Set);

gdipRegion.Dispose();


I have also written a small .NET sample project that will show how to take an existing region from a LEADTOOLS RasterImage and rotate it using the following method:

Code:
 private void RotateRegion(int angle)
      {
         RasterImage image = viewer.Image;

         using (Region gdipRegion = RasterRegionConverter.ConvertToRegion(image.GetRegion(null), null))
         {
            var bounds = gdipRegion.GetBounds(viewer.CreateGraphics());
            Matrix m = new Matrix();
            m.RotateAt(angle, new PointF(bounds.Left + (bounds.Width / 2), bounds.Top + (bounds.Height / 2)));
            gdipRegion.Transform(m);

            using (RasterRegion region = RasterRegionConverter.ConvertFromRegion(gdipRegion))
               image.SetRegion(null, region, RasterRegionCombineMode.Set);
         }


You can download the project here.
File Attachment(s):
Rotate Region Demo.zip (11kb) downloaded 89 time(s).
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.

LEAD Logo
 
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.

Powered by YAF.NET | YAF.NET © 2003-2019, Yet Another Forum.NET
This page was generated in 0.124 seconds.