The AnnUnitConverter Class is available in LEADTOOLS Document and Medical Imaging toolkits.
The
AnnUnitConverter class contains methods and properties for converting between different units of measurement.
Object Model
Syntax
Example
This example shows how to convert between AnnUnit and AnnAngularUnit in several ways.
Visual Basic | Copy Code |
---|
Private Sub AnnUnitConverter_AnnUnitConverter()
' set up the unit converter with 96 DPI
Dim converter As AnnUnitConverter = New AnnUnitConverter(96, 96)
' 200 pixels
Dim pixels As Single = 200
' convert to inches
Dim inches As Single = converter.ConvertHorizontal(pixels, AnnUnit.Pixel, AnnUnit.Inch)
' show
Dim s As String = String.Format("{0} {1} is {2} {3} at {4} DPI", pixels, AnnUnitConverter.GetUnitAbbreviation(AnnUnit.Pixel), inches, AnnUnitConverter.GetUnitAbbreviation(AnnUnit.Inch), converter.DpiX)
MessageBox.Show(s)
' 45 degrees
Dim degrees As Single = 45
' convert to radians
Dim radians As Single = AnnUnitConverter.Convert(degrees, AnnAngularUnit.Degree, AnnAngularUnit.Radian)
' show
s = String.Format("{0}{1} is {2} {3}", degrees, AnnUnitConverter.GetAngularUnitAbbreviation(AnnAngularUnit.Degree), radians, AnnUnitConverter.GetAngularUnitAbbreviation(AnnAngularUnit.Radian))
MessageBox.Show(s)
End Sub |
C# | Copy Code |
---|
private void AnnUnitConverter_AnnUnitConverter()
{
// set up the unit converter with 96 DPI
AnnUnitConverter converter = new AnnUnitConverter(96, 96);
// 200 pixels
float pixels = 200;
// convert to inches
float inches = converter.ConvertHorizontal(pixels, AnnUnit.Pixel, AnnUnit.Inch);
// show
string s = string.Format("{0} {1} is {2} {3} at {4} DPI",
pixels,
AnnUnitConverter.GetUnitAbbreviation(AnnUnit.Pixel),
inches,
AnnUnitConverter.GetUnitAbbreviation(AnnUnit.Inch),
converter.DpiX);
MessageBox.Show(s);
// 45 degrees
float degrees = 45;
// convert to radians
float radians = AnnUnitConverter.Convert(degrees, AnnAngularUnit.Degree, AnnAngularUnit.Radian);
// show
s = string.Format("{0}{1} is {2} {3}",
degrees,
AnnUnitConverter.GetAngularUnitAbbreviation(AnnAngularUnit.Degree),
radians,
AnnUnitConverter.GetAngularUnitAbbreviation(AnnAngularUnit.Radian));
MessageBox.Show(s);
} |
Inheritance Hierarchy
Requirements
Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7
See Also