In Nevron Graphics all measurement units derive from the base NMeasurementUnit class. Currently there are three types of measurement units:
-
Device - device measurement units are the units of measure of the output device. There is only one device measurement unit and it is called pixel.
-
Absolute - absolute measurement units are units that do not depend on the device, on which the image is rasterized. For example: inches and meters are absolute units, because their length does not depend on the output device.
-
Relative - relative measurement units depend on the size of "something else". In the context of the Nevron Graphics the relative measurement units depend on the size of the parent or root objects containing the object.
The type of the measurement unit is obtained from the UnitType property, which returns a value from the UnitType enumeration.
Measurement systems group related measurement units. In Nevron Graphics all measurement systems derive from the base NMeasurementSystem class. Currently there are four built-in measurement systems:
-
Graphics Measurement System - contains GDI measurement units: Pixel, Point, Display, Document, Inch and Millimeter. It is represented by the
NGraphicsMeasurementSystem class.
-
English Measurement System - contains British and American (English) measurement units: League, Mile, Furlong, Chain, Rod, Yard, Foot, Link, Hand, Inch and Line. It is represented by the
NEnglishMeasurementSystem class.
-
Metric Measurement System - contains Metric measurement units: Micrometer, Millimeter, Centimeter, Decimeter, Meter and Kilometer. It is represented by the
NMetricMeasurementSystem class.
-
Relative Measurement System - contains Relative measurement units: ParentPercentage and RootPercentage. It is represented by the
NRelativeMeasurementSystem class.
The measurement units for a concrete system can easily be obtained from the MeasurementUnits property of that system.
You can easily convert a value measured in one unit to the respective value in another unit. This is achieved with the help of the NMeasurementUnitConverter class. Typically this class is used to convert device units to/from absolute units, but it can also be used to convert relative units to/from the other two types of units.
The following example converts millimeters to pixels, based on a 300x300 dpi device resolution:
C# |
Copy Code
|
// create a converter for 300x300 dots per inch device resolution
NMeasurementUnitConverter converter = new NMeasurementUnitConverter(300, 300);
float pixelsPerMM = converter.ConvertX(NMetricUnit.Millimeter, NGraphicsUnit.Pixel, 1);
|
Visual Basic |
Copy Code
|
' create a converter for 300x300 dots per inch device resolution
Dim converter As New NMeasurementUnitConverter(300, 300)
Dim pixelsPerMM As Single = converter.ConvertX(NMetricUnit.Millimeter, NGraphicsUnit.Pixel, 1)
|
All measurements units are implemented as singletons and you can obtain their instance from the base measurement unit for each measurement system. For example:
C# |
Copy Code
|
NMeasurementUnit pixelMeasurementUnit = NGraphicsUnit.Pixel;
NMeasurementUnit inchMeasurementUnit = NEnglishUnit.Inch;
NMeasurementUnit millimeterMeasurementUnit = NMetricUnit.Millimeter;
NMeasurementUnit parentPercentageMeasurementUnit = NRelativeUnit.ParentPercentage;
|
Visual Basic |
Copy Code
|
Dim pixelMeasurementUnit As NMeasurementUnit = NGraphicsUnit.Pixel
Dim inchMeasurementUnit As NMeasurementUnit = NEnglishUnit.Inch
Dim millimeterMeasurementUnit As NMeasurementUnit = NMetricUnit.Millimeter
Dim parentPercentageMeasurementUnit As NMeasurementUnit = NRelativeUnit.ParentPercentage
|