Home › Forums › TWAIN Classic › Making a scanning preview › Re: Here is a sample of the code i hope is helps a little
August 1, 2008 at 7:45 pm #24584
ALL THIS IS IN THE MAIN PROGRAM
=======================================================================================
I set the procedures to let the source loaded for setting triplets
……….
setvalues; //<
Procedure where you set values in state before source getting enabled
Twain.Source[LoadedSource].TransferMode := Self.TransferMode;
Twain.Source[LoadedSource].EnableSource(ItemShowInterface.Checked, false);
while Twain.Source[LoadedSource].Enabled do
begin
// twain.Source[CurrentSource].SetICapUnits(tucentimeters);
Application.ProcessMessages;
end;
…..
here in setvalues;
i do something like this
setvaluefor('ICAP_SHADOW');
setvaluefor('ICAP_GAMMA');
if (tamapapel.Text='Personalizado...') and (modopreview=false) then
begin
SendCommandForm.TestResult(twain.Source[CurrentSource].SetImagelayoutFrame(fy1,fx1,fy2,fx2));
end;
==========================================================================================
THIS IS PART OF THE COMPONENT FROM DELPHITWAIN
==========================================================================================
function SetImagelayoutFrame(const fLeft,fTop,fRight,fBottom: double): TCapabilityRet;
---
//npeter: 2004.01.12
//sets the acquired area
function TTwainSource.SetImagelayoutFrame(const fLeft, fTop, fRight,fBottom: double): TCapabilityRet;
var ImageLayout: TW_IMAGELAYOUT;
fraccion:real;
begin
if not Loaded then
begin
Result := crInvalidState; {In case the source is not loaded}
exit;
end;
fillchar(ImageLayout,sizeof(TW_IMAGELAYOUT),0);
with ImageLayout.Frame do
begin
Left:=FloatToFIX32(fLeft);
Top:=FloatToFIX32(fTop);
Right:=FloatToFIX32(fRight);
Bottom:=FloatToFIX32(fBottom);
end;
{Call method and store return}
Result := ResultToCapabilityRec(Owner.TwainProc(AppInfo, @Structure,DG_IMAGE, DAT_IMAGELAYOUT, MSG_SET, @ImageLayout));
end;
if any doubt about floattofix32
function FloatToFix32 (floater: extended): TW_FIX32;
var
fracpart : extended;
begin
//Obtain numerical part by truncating the float number
Result.Whole := trunc(floater);
//Obtain fracional part by subtracting float number by
//numerical part. Also we make sure the number is not
//negative by multipling by -1 if it is negative
fracpart := floater - result.Whole;
if fracpart < 0 then fracpart := fracpart * -1;
//Multiply by 10 until there is no fracional part any longer
while FracPart - trunc(FracPart) <> 0 do fracpart := fracpart * 10;
//Return fracional part
Result.Frac := trunc(fracpart);
end;
[/code]
The full code of delphiTwain for Borland Delphi is http://delphitwain.sourceforge.net/
any doubt or anything you want just tell me