LEADTOOLS Support
Document
Document SDK Examples
HOWTO: C# example to rotate image and annotations.
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Tuesday, August 16, 2005 1:18:27 PM(UTC)
Groups: Registered, Tech Support
Posts: 46
Version: 14
Interface: .NET
Sample Type: Snippet
Development Environment: C#.NET
Keywords: annotations rotate rotation transform
The function below will allow you to rotate an image as well as the annotation container within that image. Due to the way encryption objects work, they are not supported by this function.
Code:private void RotateImageAndAnnotations( int angle, AnnContainer container, RasterImageViewer viewer )
{
// round the angle
angle %= 360;
if ( angle == 0 )
return; // nothing to do
// when we rotate an image, this is what happens:
// 1. the image is rotated around its center (width/2, height/2)
// 2. the image is translated so that its top,left position is at 0,0
// to calculate this translation, we:
// 1. find the 4 end points of the container
// 2. rotate these points
// 3. find the minimum/maximum "out of range" point
// 4. calculate the translation (amount to bring this "out of range"point back into view)
PointF[] pts =
{
new PointF( 0, 0 ),
new PointF( viewer.Image.ImageWidth, 0 ),
new PointF( viewer.Image.ImageWidth, viewer.Image.ImageHeight ),
new PointF( 0, viewer.Image.ImageHeight )
};
PointF origin = new PointF( viewer.Image.ImageWidth / 2, viewer.Image.ImageHeight / 2 );
using ( var m = new Matrix() )
{
m.RotateAt( angle, origin );
m.TransformPoints( pts );
}
float xMin = pts[0].X;
float yMin = pts[0].Y;
for ( int i = 1; i < pts.Length; i++ )
{
if ( pts[i].X < xMin )
xMin = pts[i].X;
if ( pts[i].Y < yMin )
yMin = pts[i].Y;
}
float xTranslate = -xMin;
float yTranslate = -yMin;
// now, rotate the image
new RotateCommand( angle * 100, RotateCommandFlags.Resize, RasterColor.FromGdiPlusColor( Color.White ) )
.Run( viewer.Image );
// rotate and translate the annotations
foreach ( AnnObject obj in container.Objects )
{
obj.Rotate( angle, new AnnPoint( origin ) );
if ( xTranslate != 0 || yTranslate != 0 )
obj.Translate( xTranslate, yTranslate );
}
// re-set the container bounds
container.Bounds = new AnnRectangle( 0, 0, viewer.Image.ImageWidth, viewer.Image.ImageHeight );
}
If you have any questions about this example, please post them on this thread. Thanks,
Gabriel
Edited by moderator Thursday, October 20, 2016 10:39:31 AM(UTC)
| Reason: Fixed formatting
Gabe
Developer Support
LEAD Technologies, Inc.
#2
Posted
:
Monday, February 27, 2006 1:06:58 PM(UTC)
Groups: Registered
Posts: 17
Hi,
I tried to use this methods to rotate both image and annotations. This method works fine if I run the program from the development environemnt. However, it throws an exception when I install the program in a fresh machine.
This is the exception:
"File or assembly name Leadtools.Kernel.Annotations.dll, or one of its dependencies, was not found."
Do you have any hint about this error message? or what kind of reference do I need to include besides "Leadtools.Kernel.Annotations.dll" ?
Thank you
#3
Posted
:
Tuesday, February 28, 2006 12:48:13 PM(UTC)
Groups: Registered, Tech Support
Posts: 207
Was thanked: 3 time(s) in 3 post(s)
Did you include "Leadtools.Annotations.dll"?
Travis Montgomery
Senior Sales Engineer
#4
Posted
:
Wednesday, March 1, 2006 2:51:15 PM(UTC)
Groups: Registered
Posts: 17
I aready included all of these dll file:
Leadtools.dll
Leadtools.Annotations.dll
Leadtools.Codecs.dll
Leadtools.Kernel.Annotations.dll
In my development environment, the rotation for both image and annotations works. However, it does not work if I install the program in a new machine.
Thanks
#5
Posted
:
Thursday, March 2, 2006 3:57:45 AM(UTC)
Groups: Registered, Tech Support
Posts: 207
Was thanked: 3 time(s) in 3 post(s)
What version of .NET are you using? 2002, 2003, or 2005?
What version of Windows are you deploying to?
What version of LEADTOOLS do you have? (Check Leadtools.dll example: 14.5.0.7)
Travis Montgomery
Senior Sales Engineer
#6
Posted
:
Thursday, March 2, 2006 7:02:36 AM(UTC)
Groups: Registered
Posts: 17
I'm using:
.NET 1.1, Visual Studio 2003
Windows XP
Leadtools V. 14 with 14.5.0.4 patch
#7
Posted
:
Thursday, March 2, 2006 8:42:41 AM(UTC)
Groups: Registered, Tech Support
Posts: 207
Was thanked: 3 time(s) in 3 post(s)
Add this file: Leadtools.Kernel.dll to complete the Annotation Support.
I believe the Leadtools.Codecs.dll will also need these two:
Leadtools.Kernel.Codecs.dll, Leadtools.Kernel.Codecs.Interfaces.dll
Travis Montgomery
Senior Sales Engineer
#8
Posted
:
Wednesday, March 8, 2006 8:46:23 AM(UTC)
Groups: Registered
Posts: 17
The problem is not on the dll, but on the save annotations under "AnnCodecsTagFormat.Tiff".
The problem fixed after I save the annotations under "AnnCodecsTagFormat.Serialize"
#9
Posted
:
Friday, March 10, 2006 8:46:02 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
Glad to hear you resolved the problem. If you wish to use "AnnCodecsTagFormat.Tiff", you need to deploy Leadtools.Codecs.Tif.dll.
LEADTOOLS Support
Document
Document SDK Examples
HOWTO: C# example to rotate image and annotations.
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.