ImageEn, unit imageenview

TImageEnView.SetScale

TImageEnView.SetScale


Declaration

procedure SetScale(Pixels: Integer; Value: Double; Units: TIEUnits); overload;
procedure SetScale(PixelsX: Integer; ValueX: Double; PixelsY: Integer; ValueY: Double; Units: TIEUnits); overload;


Description

Sets ScaleX and ScaleY so that the measurement tools output valid values for your image.
The scale values combined with IO.Params.DpiX and IO.Params.DpiY, determine the displayed values when measuring distances and areas (miMeasureLength, miMeasureRect or miMeasureEllipse in MouseInteractGeneral) and displaying the ruler (ShowRulers).


Measurement and Scaling

Say you have an image that is 100 DPI (dots per inch), so that when it is printed every 100 pixels print out at a size of 1 inch (2.54cm). If TImageEnView.ScaleY/Y=1, using the measurement tool, a length of 100 pixels will naturally display as 1 inch/2.54cm. But what if we have a photograph of an object where 1 inch in the image represents 1 foot (12 inches) in the real world? This would equate to a scale of 1:12, i.e. TImageEnView.ScaleY/Y = 12. Now, when you select 100 pixels, the measurement tool will report 1 foot.
Naturally it will also work the other way. If we have a detailed image that is recorded as 100 DPI (i.e. 100 pixels = 1 inch/25.4 mm), but actually 100 pixels represents 2.5mm, the scale would be 1:0.1, i.e. TImageEnView.ScaleY/Y=0.1 (alternatively, you could set the DPI as 10).

To make it easier, you can use TimageEnView.SetScale. In the first example we would use:

ImageEnView1.SetScale(100, 1, ieuFeet );

And in the second:

ImageEnView1.SetScale(100, 2.5, ieuMillimeters );


Examples

// We know that 100 pixels in our photo equals 1 foot
ImageEnView1.SetScale( 100, 1, ieuFeet );

// User has selected a square inch in the image
ImageEnView1.SetScale( ImageEnView1.SelectedRect.Width, 1,
                       ImageEnView1.SelectedRect.Height, 1,
                       ieuInches );
ImageEnView1.MouseInteractGeneral := [ miMeasureLength ];

// User has selected a 4cm square in the image
ImageEnView1.SetScale( ImageEnView1.SelectedRect.Width, 4,
                       ImageEnView1.SelectedRect.Height, 4,
                       ieuCentimeters );
ImageEnView1.MouseInteractGeneral := [ miMeasureLength ];

// Enable measuring of lengths in image (Imperial)
// Set scale of 250 pixels = one inch
ImageEnView1.SetScale( 250, 1, ieuInches );
IEGlobalSettings().DefaultMeasureUnit := ieuInches;
ImageEnView1.Update();
ImageEnView1.MouseInteractGeneral := [ miMeasureLength ];

// Enable measuring of lengths in image (Metric)
// Set 100 pixels = 4cm
ImageEnView1.SetScale( 100, 4, ieuCentimeters );
IEGlobalSettings().DefaultMeasureUnit := ieuCentimeters;
ImageEnView1.Update();
ImageEnView1.MouseInteractGeneral := [ miMeasureLength ];


Demos

Demo  Demos\ImageAnalysis\MeasureIt\MeasureIt.dpr
Demo  Demos\Other\ImageEnViewRulers\ImageEnViewRulers.dpr


See Also

 MouseInteractGeneral
 OnMeasure