// Setup points for the ruler.
ImGearPoint[] igPoints = new ImGearPoint[4];
igPoints[0] = new ImGearPoint(10, 10);
igPoints[1] = new ImGearPoint(10, 20);
igPoints[2] = new ImGearPoint(20, 15);
igPoints[3] = new ImGearPoint(30, 10);
// 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.
ImGearARTPolyRuler polyRuler = new ImGearARTPolyRuler(igPoints, color, imageResolution);
// Let's change measurement units to inches.
imageResolution.ConvertUnits(ImGearResolutionUnits.INCHES);
// Set number of pixels per 1 inch.
polyRuler.AspectDenominatorX = 1 * (int)Math.Round((double)imageResolution.XNumerator / (double)imageResolution.XDenominator);
polyRuler.AspectDenominatorY = 1 * (int)Math.Round((double)imageResolution.YNumerator / (double)imageResolution.YDenominator);
// Set 1 inch scale.
polyRuler.AspectNumeratorX = 1;
polyRuler.AspectNumeratorY = 1;
polyRuler.Label = "%d in";
// Now change the measurement units back to the mm.
imageResolution.ConvertUnits(ImGearResolutionUnits.METERS);
// Set number of pixels per 1 meter.
polyRuler.AspectDenominatorX = 1 * (int)Math.Round((double)imageResolution.XNumerator / (double)imageResolution.XDenominator);
polyRuler.AspectDenominatorY = 1 * (int)Math.Round((double)imageResolution.YNumerator / (double)imageResolution.YDenominator);
// Set 1 mm scale.
polyRuler.AspectNumeratorX = 1000;
polyRuler.AspectNumeratorY = 1000;
polyRuler.Label = "%d mm";
igARTPage.AddMark(polyRuler, ImGearARTCoordinatesType.IMAGE_COORD);