// Setup start and endpoint for the ruler.
ImGearPoint startPoint = new ImGearPoint(10, 10);
ImGearPoint endPoint = new ImGearPoint(igPage.DIB.Width / 2, igPage.DIB.Height / 2);
// Setup color for the ruler.
ImGearRGBQuad color = new ImGearRGBQuad(0, 255, 0);
// Get and initialize image resolution for the ruler.
ImGearResolution imageResolution = new ImGearResolution(
igPage.DIB.ImageResolution.XNumerator,
igPage.DIB.ImageResolution.XDenominator,
igPage.DIB.ImageResolution.YNumerator,
igPage.DIB.ImageResolution.YDenominator,
igPage.DIB.ImageResolution.Units);
// Create ruler, note that the ruler is always created with measurement units set to mm
// and it doesn't depend on ImGearResolution measurement units.
ImGearARTRuler ruler = new ImGearARTRuler(startPoint, endPoint, color, imageResolution);
// Let's change measurement units to inches.
imageResolution.ConvertUnits(ImGearResolutionUnits.INCHES);
// Set number of pixels per 1 inch.
ruler.AspectDenominatorX = 1 * (int)Math.Round((double)imageResolution.XNumerator / (double)imageResolution.XDenominator);
ruler.AspectDenominatorY = 1 * (int)Math.Round((double)imageResolution.YNumerator / (double)imageResolution.YDenominator);
// Set 1 inch scale.
ruler.AspectNumeratorX = 1;
ruler.AspectNumeratorY = 1;
ruler.Label = "%d in";
// Now change the measurement units back to the mm.
imageResolution.ConvertUnits(ImGearResolutionUnits.METERS);
// Set number of pixels per 1 meter.
ruler.AspectDenominatorX = 1 * (int)Math.Round((double)imageResolution.XNumerator / (double)imageResolution.XDenominator);
ruler.AspectDenominatorY = 1 * (int)Math.Round((double)imageResolution.YNumerator / (double)imageResolution.YDenominator);
// Set 1 mm scale.
ruler.AspectNumeratorX = 1000;
ruler.AspectNumeratorY = 1000;
ruler.Label = "%d mm";
igARTPage.AddMark(ruler, ImGearARTCoordinatesType.IMAGE_COORD);