Home › Forums › TWAIN Classic › Making a scanning preview
- This topic has 13 replies, 2 voices, and was last updated 15 years, 9 months ago by GaaraTheKasekage.
- AuthorPosts
hello everybody I hope to get some help, see I m in the middle of one big problem I m using Delphi 7 and a component called DelphiTwain from Gustavo Daud but it seems that a procedure that he did SetImageLayoutFrame(a,b,c,d) does not work very well but i must say his work is great or maybe I m wrong in something see for example it looks like that if a =1.6 inches seems that i send an instruction a=1 Inch. i dont know what happens to .6 i debugged and it separates and seems that he sends the var into two parts a whole and a frac part in conclusion I want to acquire correctly more precisely because everytime I try it does not even get close I tried to use different ICAP_UNIT but not success always get the same that is Inches has anyone had a similar problem?
Could be that his library sends 1.6 to the scanner and the scanner rounds to the closest supported value, it wouldn’t be unheard of.
Or you could be sending another triplet that resets the frame.list all of the triplets you send in order, and if you’d like me to test this in my code then install a kodak i30 in simulation mode and test your code again. this way we’d be looking at the same triplets on the same hardware with different librarys.
and the whole/fraction thing – it’s how you send twain fix32 values, also common.
.
I will give you the code and trip`lets but first I gotta to the pc that has de code 🙂 thanks
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 thissetvaluefor('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 floattofix32function 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 meWhat device(s) are you testing this on?
Have you run twister or the twain toolkit on the device(s) to verify that code other than your own does something that your code|library doesn’t do?
.
I downloaded twain toolkit twister is unknownw for me I used twain toolkit for testing where can I check specifically this area on the twain toolkit code?
twister is a dosadi tool (free) that produces a report on a device driver’s (lack of) support for twain. http://www.dosadi.com/twister.htm
run the tool and post the report here. Without dosadi, a lot of twain applications wouldn’t exist and learning twain would take much longer.
Also of interest on their site is the ‘vendors & devices’ http://www.dosadi.com/vendors.htm page where you can read some of their comments.
And then of course their twister report archive http://www.dosadi.com/twister-reports.php is invaluble if you ever face the question “what devices will your application work with”In the twain toolkit I wasn’t thinking you’d check your code so much as run it and send all of the triplets you are sending in code and see (by sending a get after each set) if the driver is accepting the triplets you’re sending or not.
this is all just verification if your code even needs work, seems that it could be the case that the code is fine and that the vendor’s driver isn’t doing quite what the spec says.
.
Start of Twister TWAIN Analysis
Analysis Started: 2008.08.04 at 08:24:27
Twister Version: 1.05.004— TW_IDENTITY block —
Product Name: Xerox WorkCentre PE220 Series
Product Family: Xerox WorkCentre PE220 Series
Manufacturer: Xerox
Software Version: 2.1 (“2.01.57”)
TWAIN Protocol Version: 1.9— DataSource File Version Info —
File: C:WINDOWSTwain_32XeroxWCPE220OEMDS.DS
File Timestamp: 2008.01.31 19:45:10
** unable to get version info from C:WINDOWSTwain_32XeroxWCPE220OEMDS.DS **Section 1. Capabilities
If a capability does not appear in the following list, then the device
reported it as unsupported in conformance with the TWAIN standard.CAP_XFERCOUNT:
GET………….int16 -1
GETCURRENT……int16 -1
GETDEFAULT……int16 -1ICAP_COMPRESSION:
GET………….uint16 TWCP_NONE
GETCURRENT……uint16 TWCP_NONE
GETDEFAULT……uint16 TWCP_NONE
SET………….TWCP_NONE okICAP_PIXELTYPE:
GET………….uint16 ENUM{ TWPT_BW, TWPT_GRAY, TWPT_RGB, TWPT_PALETTE }
Current: TWPT_RGB, Default: TWPT_RGB
GETCURRENT……uint16 TWPT_RGB
GETDEFAULT……uint16 TWPT_RGB
SET………….TWPT_BW ok
SET………….TWPT_GRAY ok
SET………….TWPT_RGB ok
SET………….TWPT_PALETTE okICAP_UNITS:
GET………….uint16 TWUN_INCHES
GETCURRENT……uint16 TWUN_INCHES
GETDEFAULT……uint16 TWUN_INCHES
SET………….TWUN_INCHES okICAP_XFERMECH:
GET………….uint16 ENUM{ TWSX_NATIVE, TWSX_FILE, TWSX_MEMORY }
Current: TWSX_NATIVE, Default: TWSX_NATIVE
GETCURRENT……uint16 TWSX_NATIVE
GETDEFAULT……uint16 TWSX_NATIVE
SET………….TWSX_NATIVE ok
SET………….TWSX_FILE ok
SET………….TWSX_MEMORY okCAP_FEEDERENABLED:
GET………….bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool TRUE
SET(FALSE)……ok
SET(TRUE)…….okCAP_FEEDERLOADED:
GET………….bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool FALSECAP_SUPPORTEDCAPS:
GET………….uint16 ARRAY[ CAP_XFERCOUNT, CAP_UICONTROLLABLE,
CAP_DEVICEONLINE, ICAP_PHYSICALHEIGHT, ICAP_PHYSICALWIDTH,
ICAP_COMPRESSION, ICAP_PLANARCHUNKY, ICAP_PIXELFLAVOR,
ICAP_BITORDER, ICAP_XFERMECH, ICAP_UNITS,
ICAP_XRESOLUTION, ICAP_YRESOLUTION, ICAP_PIXELTYPE,
ICAP_BITDEPTH, CAP_INDICATORS, ICAP_IMAGEFILEFORMAT,
ICAP_SUPPORTEDSIZES, ICAP_MINIMUMHEIGHT,
ICAP_MINIMUMWIDTH, ICAP_XNATIVERESOLUTION,
ICAP_YNATIVERESOLUTION, ICAP_XSCALING, ICAP_YSCALING,
ICAP_BRIGHTNESS, ICAP_CONTRAST, ICAP_HIGHLIGHT,
ICAP_SHADOW, ICAP_ROTATION, ICAP_GAMMA, CAP_FEEDERENABLED,
CAP_PAPERDETECTABLE, CAP_AUTOFEED, CAP_FEEDERLOADED,
CAP_CLEARPAGE, CAP_DUPLEX, CAP_DUPLEXENABLED,
ICAP_FLIPROTATION, ICAP_TILES, CAP_FEEDERALIGNMENT,
CAP_FEEDERORDER, CAP_SUPPORTEDCAPS ]
GETCURRENT……ditto
GETDEFAULT……dittoCAP_AUTOFEED:
GET………….bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool TRUE
SET(FALSE)…..?failed
SET(TRUE)…….okCAP_CLEARPAGE:
GET………….bool FALSE
GETCURRENT……bool FALSE
GETDEFAULT……bool FALSE
SET………….not tested due to side effects.CAP_INDICATORS:
GET………….bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool TRUE
SET(FALSE)……ok
SET(TRUE)…….okCAP_PAPERDETECTABLE:
GET………….bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool FALSECAP_UICONTROLLABLE:
GET………….bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool TRUECAP_DEVICEONLINE:
GET………….bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool TRUECAP_DUPLEX:
GET………….uint16 TWDX_NONE
GETCURRENT……uint16 TWDX_NONE
GETDEFAULT……uint16 TWDX_NONECAP_DUPLEXENABLED:
GET…………*not supported.CAP_FEEDERALIGNMENT:
GET………….uint16 TWFA_RIGHT
GETCURRENT……uint16 TWFA_RIGHT
GETDEFAULT……uint16 TWFA_RIGHT
SET…………?TWFA_RIGHT failedCAP_FEEDERORDER:
GET………….uint16 0
GETCURRENT……uint16 0
GETDEFAULT……uint16 0
SET…………?0 failedICAP_BRIGHTNESS:
GET………….fix32 From -1000 To 1000 Step 10, Current: 0, Default: 0
GETCURRENT……fix32 0
GETDEFAULT……fix32 0
SET………….0 ok
SET………….-1000 ok
SET………….-500 ok
SET………….500 ok
SET………….1000 okICAP_CONTRAST:
GET………….fix32 From -1000 To 1000 Step 10, Current: 0, Default: 0
GETCURRENT……fix32 0
GETDEFAULT……fix32 0
SET………….0 ok
SET………….-1000 ok
SET………….-500 ok
SET………….500 ok
SET………….1000 okICAP_GAMMA:
GET………….fix32 1
GETCURRENT……fix32 1
GETDEFAULT……fix32 1
SET………….1 okICAP_HIGHLIGHT:
GET………….fix32 From 1 To 255 Step 1, Current: 255, Default: 255
GETCURRENT……fix32 255
GETDEFAULT……fix32 255
SET………….255 ok
SET………….1 ok
SET………….64 ok
SET………….128 ok
SET………….191 okICAP_IMAGEFILEFORMAT:
GET………….uint16 TWFF_BMP
GETCURRENT……uint16 TWFF_BMP
GETDEFAULT……uint16 TWFF_BMP
SET………….TWFF_BMP okICAP_PHYSICALWIDTH:
GET………….fix32 8.5
GETCURRENT……fix32 8.5
GETDEFAULT……fix32 8.5ICAP_PHYSICALHEIGHT:
GET………….fix32 14
GETCURRENT……fix32 14
GETDEFAULT……fix32 14ICAP_SHADOW:
GET…………*fix32 From 0 To 254 Step 1, Current: 0, Default: 0
GETCURRENT……fix32 0
GETDEFAULT……fix32 0
SET………….0 ok
SET………….63 ok
SET………….127 ok
SET………….190 ok
SET………….254 okICAP_XNATIVERESOLUTION:
GET………….fix32 600ICAP_YNATIVERESOLUTION:
GET………….fix32 600ICAP_XRESOLUTION:
GET………….fix32 ENUM{ 75, 100, 150, 200, 300, 600, 1200, 2400, 4800
} Current: 300, Default: 300
GETCURRENT……fix32 300
GETDEFAULT……fix32 300
SET………….300 ok
SET………….75 ok
SET………….150 ok
SET………….1200 ok
SET………….4800 okICAP_YRESOLUTION:
GET………….fix32 ENUM{ 75, 100, 150, 200, 300, 600, 1200, 2400, 4800
} Current: 300, Default: 300
GETCURRENT……fix32 300
GETDEFAULT……fix32 300
SET………….300 ok
SET………….75 ok
SET………….150 ok
SET………….1200 ok
SET………….4800 okICAP_TILES:
GET…………*bool TRUE
GETCURRENT……bool TRUE
GETDEFAULT……bool TRUE
SET(FALSE)……ok
SET(TRUE)…….okICAP_BITORDER:
GET………….uint16 TWBO_MSBFIRST
GETCURRENT……uint16 TWBO_MSBFIRST
GETDEFAULT……uint16 TWBO_MSBFIRST
SET………….TWBO_MSBFIRST okICAP_PIXELFLAVOR:
GET………….uint16 TWPF_CHOCOLATE
GETCURRENT……uint16 TWPF_CHOCOLATE
GETDEFAULT……uint16 TWPF_CHOCOLATE
SET………….TWPF_CHOCOLATE okICAP_PLANARCHUNKY:
GET………….uint16 TWPC_CHUNKY
GETCURRENT……uint16 TWPC_CHUNKY
GETDEFAULT……uint16 TWPC_CHUNKY
SET………….TWPC_CHUNKY okICAP_ROTATION:
GET………….fix32 ENUM{ 0, 90, 180, 270 } Current: 0, Default: 0
GETCURRENT……fix32 0
GETDEFAULT……fix32 0
SET………….0 ok
SET………….90 ok
SET………….180 ok
SET………….270 okICAP_SUPPORTEDSIZES:
GET………….uint16 ENUM{ TWSS_USLETTER, TWSS_USLEGAL,
TWSS_USEXECUTIVE, TWSS_USSTATEMENT,
TWSS_A4(TWSS_A4LETTER), TWSS_A5, TWSS_ISOB5,
TWSS_B5LETTER/TWSS_JISB5, TWSS_JISB6, TWSS_C5 } Current:
TWSS_A4(TWSS_A4LETTER), Default: TWSS_A4(TWSS_A4LETTER)
GETCURRENT……uint16 TWSS_A4(TWSS_A4LETTER)
GETDEFAULT……ditto
SET………….TWSS_USLETTER ok
SET………….TWSS_USLEGAL ok
SET………….TWSS_USEXECUTIVE ok
SET………….TWSS_USSTATEMENT ok
SET………….TWSS_A5 ok
SET………….TWSS_ISOB5 ok
SET………….TWSS_B5LETTER/TWSS_JISB5 ok
SET………….TWSS_C5 okICAP_XSCALING:
GET………….fix32 From 0.25 To 4 Step 0.009995, Current: 1, Default: 1
GETCURRENT……fix32 1
GETDEFAULT……fix32 1
SET………….0.25 ok
SET………….1.179489 ok
SET………….2.118973 ok
SET………….3.058456 ok
SET………….3.99794 okICAP_YSCALING:
GET………….fix32 From 0.25 To 4 Step 0.009995, Current: 1, Default: 1
GETCURRENT……fix32 1
GETDEFAULT……fix32 1
SET………….0.25 ok
SET………….1.179489 ok
SET………….2.118973 ok
SET………….3.058456 ok
SET………….3.99794 okICAP_BITDEPTH:
GET………….uint16 8
GETCURRENT……uint16 8
GETDEFAULT……uint16 8ICAP_MINIMUMHEIGHT:
GET………….fix32 0.099991ICAP_MINIMUMWIDTH:
GET………….fix32 0.099991ICAP_FLIPROTATION:
GET………….uint16 0
GETCURRENT……uint16 0
GETDEFAULT……uint16 0
SET………….0 okSection 2. Image Layout
DG_IMAGE, DAT_IMAGELAYOUT, MSG_RESET => OK.
DG_IMAGE, DAT_IMAGELAYOUT, MSG_GETDEFAULT => ( 0, 0, 8.5, 14).
DG_IMAGE, DAT_IMAGELAYOUT, MSG_GET => ( 0, 0, 8.5, 14).
DG_IMAGE, DAT_IMAGELAYOUT, MSG_SET (1.06, 2.33, 2.12, 4.66) => OK.
Scanning to verify image layout: OK
Returned image is 105 x 231 pixels, with resolution of 100 x 100 DPI
Requested resolution was: 100 x 100 DPI
Width = 1.05 (versus requested 1.06)
Height = 2.31 (versus requested 2.33)
Questions [? items]
(0) Could not set CAP_AUTOFEED to FALSE.
(1) Could not set CAP_FEEDERALIGNMENT to TWFA_RIGHT.
(2) Could not set CAP_FEEDERORDER to 0.
Compliance Issues [* items]
(0) CAP_DUPLEXENABLED: GET failed, but cap is in CAP_SUPPORTEDCAPS.
(1) ICAP_SHADOW: GET maximum value not 255.
(2) ICAP_TILES: GET after open, current value is not FALSE.
(3) CAP_FEEDERLOADED: RESET succeeded when it should fail.
(4) CAP_FEEDERALIGNMENT: RESET failed when it should succeed.
(5) CAP_FEEDERORDER: RESET failed when it should succeed.
(6) CAP_FEEDERALIGNMENT: SET failed on all values.
(7) CAP_FEEDERORDER: SET failed on all values.
End Twister Analysis.
😀and what happens when you try to send the set triplet with the twain toolkit?
And if you send the Get triplet after you send the set (assuming the Set is successful) what does the Get return for a value?.
I send DG_IMAGE,DAT_IMAGELAYOUT,MSG_SET
I tried to put these values
Frame.Left=1.0897
Frame.Top=1.266
Frame.Right=2.106
Frame.Bottom=2.496
DocumentNumber=
PageNumber=
FrameNumber=I hit Send and then does this
returned:TWRC_SUCCESS
Frame.Left=0.000
Frame.Top=0.000
Frame.Right=0.000
Frame.Bottom=0.000
DocumentNumber=1
PageNumber=1
FrameNumber=1and when enabled appeared the UI and atry to digitalize and does nothing
what do you get when you send DG_IMAGE,DAT_IMAGELAYOUT,MSG_GET after you send DG_IMAGE,DAT_IMAGELAYOUT,MSG_SET ?
when i set in MSG_GET
I hit Send and then does this
returned:TWRC_SUCCESS
Frame.Left=0.000
Frame.Top=0.000
Frame.Right=0.000
Frame.Bottom=0.000
DocumentNumber=1
PageNumber=1
FrameNumber=1Can be this part of the problem maybe is not the triplet at all maybe it is the bmp watch this code:
function TTwainSource.PrepareMemXfer(var BitmapHandle: HBitmap; var PixelType: TW_INT16): TW_UINT16;
const
PixelColor: Array[TTwainPixelFlavor] of Array[0..1] of Byte =
((0, $FF), ($FF, 00), (0, $FF));
var
Handle: HGlobal;
Info: TW_IMAGEINFO;
Setup: TW_SETUPMEMXFER;
structsize, index, Size, Blocks: Integer;
XRes, YRes: Extended;
Pal : TW_PALETTE8;
vUnit : TTwainUnit;
vUnits: TTwainUnitSet;
Dib : pBitmapInfo;
PixelFlavor: TTwainPixelFlavor;
PixelFlavors: TTwainPixelFlavorSet;
DC: HDC;
Data : Pointer;
begin
{First of all, get information on the image being acquired}
Result := Owner.TwainProc(AppInfo, @Structure, DG_IMAGE, DAT_IMAGEINFO,MSG_GET, @Info);
if Result <> TWRC_SUCCESS then exit;
{Calculate image size}
with Info do
size := ((((ImageWidth * BitsPerPixel + 31) div 32)*4) * info.ImageLength);
{Obtain image buffer transference sizes}
Owner.TwainProc(AppInfo, @Structure, DG_CONTROL, DAT_SETUPMEMXFER, MSG_GET, @Setup);
blocks := (size div Integer(setup.Preferred));
size := (blocks + 1) * Integer(setup.Preferred);
{Prepare new bitmap}
structsize := size + sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
Handle := GlobalAlloc(GHND, StructSize);
Dib := GlobalLock(Handle);
Fillchar(Dib^, structsize, #0);
{Fill image information}
Dib^.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
Dib^.bmiHeader.biWidth := info.ImageWidth;
Dib^.bmiHeader.biHeight := info.ImageLength;
{Only 1 plane supported}
Dib^.bmiHeader.biPlanes := 1;
Dib^.bmiHeader.biBitCount := info.BitsPerPixel;
{No compression}
Dib^.bmiHeader.biCompression := BI_RGB;
Dib^.bmiHeader.biSizeImage := Size;
{Adjust units}
XRes := Fix32ToFloat(Info.XResolution);
YRes := Fix32ToFloat(Info.YResolution);
GetICapUnits(vUnit, vUnits);
case vUnit of
tuInches: begin
Dib^.bmiHeader.biXPelsPerMeter := Trunc((XRes*2.54)*100);
Dib^.bmiHeader.biYPelsPerMeter := Trunc((YRes*2.54)*100);
end;
tuCentimeters: begin
Dib^.bmiHeader.biXPelsPerMeter := Trunc(XRes*100);
Dib^.bmiHeader.biYPelsPerMeter := Trunc(YRes*100);
end
else begin
Dib^.bmiHeader.biXPelsPerMeter := 0;
Dib^.bmiHeader.biYPelsPerMeter := 0;
end
end {case vUnits of};
{Now it should setup the palette to be used by the image}
{by either building a definied palette or retrieving the}
{image's one}
Did u do something like this?
I can T do anything!!!
- AuthorPosts