Ok i have been able to create something that seems to work.
Have created a preview form with a Timageenview inside (autofit=true, mouseinteract.miselect=true)
In this form i can do a preview using the following code:
img.io.twainparams.xresolution.currentvalue:=72;
img.io.twainparams.yresolution.currentvalue:=72;
img.io.TwainParams.VisibleDialog:=false;
img.IO.Acquire;
Later i ca get the selection size using the SelectedRect property.
In this form i have placed two edit (named width_edit and height_edit) components where the user can type the WIDTH and the HEIGHT of the selection (in centimeters)
I want to show the current height and width of the selection so have defined this event:
procedure Tmypreviewform.imgSelectionChanging(Sender: TObject);
var
w,h:integer;
begin
w:=img.SelectedRect.width;
h:=img.SelectedRect.height;
jfcform1.BeginAssign;
try
width_edit.Value:=(w/72)*2.54;
height_edit.Value:=(h/72)*2.54;
finally
jfcform1.EndAssign;
end;
end;
The edit components have an onchange event attached that contains the code to update the selection rectangle:
procedure Tmypreviewform.larghezza_editChange(Sender: TObject);
var
x1,y1,x2,y2:integer;
begin
x1:=img.SelectedRect.x;
y1:=img.SelectedRect.y;
x2:=x1+trunc(width_edit.asvalue*72/2.54);
y2:=y1+trunc(height_edit.asvalue*72/2.54);
img.SelectionBase := iesbBitmap;
img.Select(x1,y1,x2,y2);
end;
I have a small problem that i will try to explain.
If i move the selection using the mouse and the onselectionchange event is fired again the edit components are set with a value that is a bit different from the typed one.
For example, if i type 5 cm, when the rectangle is moved by the mouse the value is changed in 4.97 cm
I would like to avoid this.
Any suggestion ?
thanks