#1
Posted
:
Monday, October 17, 2016 4:06:40 PM(UTC)
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.
#2
Posted
:
Tuesday, October 18, 2016 5:48:31 AM(UTC)
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:34:54 AM(UTC)
Groups: Manager, Tech Support, Administrators
Posts: 218
Was thanked: 12 time(s) in 12 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.
Hadi Chami
Developer Support Manager
LEAD Technologies, Inc.
![LEAD Logo LEAD Logo](https://www.leadtools.com/images/new-site-images/leadtools-logo-header.png)
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.