Nevron .NET Vision
Framework / Presentation Layer / Graphics / Measurement Units / Overview

In This Topic
    In This Topic

    A measurement unit is a standardized quantity of a physical property, used as a factor to express occurring quantities of that property. In graphics measurement units are typically used to express the length, size or location of objects (i.e. some object dimensions). That is why the measurement units and systems implemented in Nevron Graphics focus on the units, which are used to measure distance - there are for example measurement units, which measure weight (e.g. gram, kilogram), but they are irrelevant to graphics.

     Measurement Units

    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

    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.

     Measurement Units Conversion

    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:

    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)
     Working with Measurement Units

    All measurements units are implemented as singletons and you can obtain their instance from the base measurement unit for each measurement system. For example:

    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
    See Also