Article

From:
To:
George Wynne
Subject:
Re: scanpage demo bug
Newsgroup:
imagelib_corporate_suite

Re: scanpage demo bug

Hi George,
GetInfoAndType is used to supply the PMultiImage.Bxxx information, and it
uses a filename from a loaded file (maybe a stream also?).  ScanImage only
places a bitmap in the PMultiImage.  You need to save it.  Look at the
examples for multi-page scanning, or for downloading from a camera.  That
will probably be a better solution for you.  Below is an example Jan
recently put on the NG.
Jim
Gabe

Yes, is same process as with sheedfeeder scanner

//////// // // // Part of Imagelib VCL/DLL Library Corporate Suite 6.0 // // // // All rights reserved. (c) Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001. // // SkyLine Tools a division by Creative Development LTD. // // // // Created by: Jan Dekkers, // // Jillian Pinsker, // // Reginald Armond, // // Che-Chern Lin, // // Alex Zitser, // // Charles Ye, // // Song Han, // // Vitaly Bondarenko, // // Jane Scarano, // // Misha Popov, // // Alexander Kmeth; // // // // and many others who provided feedback, gave tips and comments. // // // // Call 1-800 404-3832 or 1-818 346-4200 to order ImageLib Corp. Suite. // // // ////////
unit UMU_Scan;
{Includes settings to compile in either 16 or 32 bit} {$I DEFILIB.INC}
interface (*-------------------------------------------------------------------------- -
---------------------------------------------------------------------------* ) uses   Windows,   ComCtrls,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   DLL96V1,   DLLSP96,   Dialogs,   StdCtrls,   Buttons,   ExtCtrls,   TMultiP,   Gauges,   Spin,   Mask,   Utw_cap,   Printers,   MMOpen,   MMSave,   FileTools, Menus;


type   TTwainForm = class(TForm)     Panel1: TPanel;     Panel2: TPanel;     Panel3: TPanel;     Label1: TLabel;     Label3: TLabel;     Label4: TLabel;     nPages: TSpinEdit;     NBright: TSpinEdit;     NCont: TSpinEdit;     SelectSourceBtn: TSpeedButton;     ScanImagesBtn: TSpeedButton;     Panel4: TPanel;     Label2: TLabel;     Label5: TLabel;     Label6: TLabel;     Label7: TLabel;     Label8: TLabel;     TopE: TMaskEdit;     LeftE: TMaskEdit;     RightE: TMaskEdit;     BotE: TMaskEdit;     DPI: TSpinEdit;     Label9: TLabel;     Scol: TComboBox;     SaveDialog: TMMSaveDialog;     Label10: TLabel;     StretchImagewithRatioBtn: TSpeedButton;     ExitBtn: TSpeedButton;     Panel5: TPanel;     OpenBtn: TSpeedButton;     ScanDocumentsBtn: TSpeedButton;     OpenDialog1: TMMOpenDialog;     PrintDialog1: TPrintDialog;     PrinterSetupDialog1: TPrinterSetupDialog;     Label11: TLabel;     CheckBox4: TCheckBox;     PMultiImage1: TPMultiImage;     Button1: TButton;     StatusBar1: TStatusBar;     ProgressBar1: TProgressBar;     UIC: TComboBox;     Label12: TLabel;     Label13: TLabel;     MainMenu1: TMainMenu;     Help1: TMenuItem;     Exit1: TMenuItem;     procedure ScanImages(Sender: TObject);     procedure SelectSource(Sender: TObject);     procedure MultiplePagesClick(Sender: TObject);     procedure PMultiImage1Rubberband(Sender: TObject; Button: TMouseButton;       Shift: TShiftState; X, Y, XX, YY: Integer);     procedure ScanLoc(Sender: TObject);     procedure FormCreate(Sender: TObject);     procedure SaveBtnClick(Sender: TObject);     procedure ExitBtnClick(Sender: TObject);     procedure StretchImageClick(Sender: TObject);     procedure OpenBtnClick(Sender: TObject);     procedure PMultiImage1Progress(Sender : TObject;                                    Progress : Smallint;
PMessage : String;                                var CancelProcess : Boolean);     procedure CheckBox4Click(Sender: TObject);     procedure Button1Click(Sender: TObject);     procedure Help1Click(Sender: TObject);     procedure Exit1Click(Sender: TObject);   private     { Private declarations }   public     { Public declarations }     scLeft,     scTop,     scRight,     scBottom : Real;     InCallBackCall : Boolean;     procedure DisEn(Enb : Boolean);   end;
var   TwainForm: TTwainForm;
implementation

{------------------------------------------------------------------------ {This is an update callback routine. To cancel loading return 0 else return a 1; ------------------------------------------------------------------------} function ProgressCall(Progress : SmallInt; VObject : Longint): SmallInt; CDECL; export; begin      if VObject <> 0 then result:=TPMultiImage(VObject).ProgressStatus(Progress)       else      result:=1; end;
{$R *.DFM}
(******************************************************************
******************************************************************) procedure TTwainForm.PMultiImage1Progress(Sender : TObject;                                           Progress : Smallint;                                           PMessage : String;                                       var CancelProcess : Boolean); begin     CancelProcess := Application.Terminated;     {Process the First call}     if Progress = 0 then begin      ProgressBar1.Position:=0;      Application.ProcessMessages;     end;
    {Process the Last call}     if Progress > 99 then begin      ProgressBar1.Position:=Progress;     {Set the message caption}      StatusBar1.Panels[0].Text := '';      Application.ProcessMessages;      exit;     end;
    {Some speed improvement when only processing each fifth call}     if Progress > ProgressBar1.Position+5 then begin      ProgressBar1.Position:=Progress;      {Set the message caption}      StatusBar1.Panels[0].Text:='Status '+PMessage;      Application.ProcessMessages;     end; end;
(******************************************************************
******************************************************************) procedure TTwainForm.FormCreate(Sender: TObject); begin     scLeft :=0;     scTop :=0;     scRight :=8.5;     scBottom :=11;     Scol.ItemIndex:=3;     UIC.ItemIndex:=1;

    {This function will set a name when lowlevel scan is applied in the twain progress window}     //SetNameForTwain('Bogus_Name_Here'); end;
(****************************************************************** Scan one page ******************************************************************) procedure TTwainForm.ScanImages(Sender: TObject); begin   DisEn(false);   try    PMultiImage1.ScanImage(Handle);   finally    DisEn(True);   end; end;
(****************************************************************** select scanner ******************************************************************) procedure TTwainForm.SelectSource(Sender: TObject); begin   DisEn(false);   try    PMultiImage1.SelectScanner(Handle);   finally    DisEn(True);   end; end;
(*************************************************************************** *** {This is a twain callback routine used when Low Level scanning multiple pages  from a scanner with a ADF sheetfeeder or with user interface.} **************************************************************************** ****) function TwainDibCall(HDIB : Thandle; d_object : longint): Smallint; CDECL; export; var    Resolution : SmallInt;    hBMP : HBitmap;    HPAL : HPalette; begin   {Indicate that we are inside the call back and doing something}   TwainForm.InCallBackCall := True;     {Set options to save the file}     Resolution:=1;     case TwainForm.Scol.ItemIndex of       0: begin             Resolution:=1;          end;       1: begin             Resolution:=8;          end;       2: begin             Resolution:=8;          end;       3: begin             Resolution:=GetDeviceRes(TwainForm.PMultiImage1.Canvas.Handle);          end;     end;
    Showmessage('NOTE: in TwainDibCall. Add your code here to save to individual jpegs');     {Save it to a jpeg file. This is faster then displaying it first }     //putjpgfiledib(ExtractFilePath(Application.Exename)+'TEMP.JPG',     putjpgfiledib(FindFilePath(Application.ExeName, 3, 'TEMP\TEMP.JPG'),                   50,                   5,                   Resolution,                   HDIB,                   LongInt(TwainForm.PMultiImage1), //use the PMultiImage1 events handler                   ProgressCall);//use the ProgressCall which points to PMultiImage1 events handler
    //This will display the DIB {******It is faster to save it without displaying it******}     //SLOW     //if HDIB > 0 then begin     // hDIBTODDB(HDIB, hBMP, HPAL);     // TwainForm.PMultiImage1.Picture.Bitmap.Handle:=hBMP;     // TwainForm.PMultiImage1.Picture.Bitmap.Palette:=HPAL;     //end;
    {Unlock DIB Handle and Free Memory of DIB}     if (GMEM_LOCKCOUNT AND GlobalFlags(HDIB) > 0) then      GlobalUnlock(HDIB);     GlobalFree(HDIB);
    {Let the app know we are not in the callbac anymore}     TwainForm.InCallBackCall := False;
    TwainForm.ProgressBar1.Position:=0;     result:=1; end;
(****************************************************************** Scan multiple pages ******************************************************************) procedure TTwainForm.MultiplePagesClick(Sender: TObject); var   MyPixType, Resolution : Integer;   Bitmap : TBitmap;   nFlags : Integer; begin  Resolution:=GetDeviceRes(PMultiImage1.Picture.Bitmap.Canvas.Handle);
 MyPixType:=TW_BW;
 case Scol.ItemIndex of       0: begin              MyPixType:=TW_BW;              Resolution:=1;          end;       1: MyPixType:=TW_GRAY;       2: MyPixType:=TW_PALETTE;       3: MyPixType:=TW_RGB;  end;  DisEn(false);
 nFlags:=0;
 case UIC.ItemIndex of   {In the DLL we check it as follow      ->ShowUI = nFlags & TW_SHOWUI;      ->UseADF = nFlags & TW_USEADF;}       0 : nFlags:=0;       1 : nFlags := TW_SHOWUI;       2 : nFlags:=0;       3 : nFlags := TW_SHOWUI or TW_USEADF;       4 : nFlags := TW_USEADF;  end;

 try  {Reset in callback}  InCallBackCall := False;
 //NOTE: FOR DIGITAL CAMARAS SET PAGES TO 10000 EXACTLY AND FLAG WITH TW_SHOWUI.  //SOME CAMARAS (E.G. THE DC120) DON'T LIKE TO NEGOTIATE THE CAP_XFERCOUNT  //WHICH RESULTS IN A LOCK-UP.
 //Most digital camaras do IGNORE the scleft, sctop, scright, scbottom, DPI, Bright and Contrast  //values simple because they have their own way of setting these in their datasource.
 if not LowLevelDibScan(Bitmap, {Return bitmap if scanning 1 page without Twain callback}                         scLeft, {Left in Inches or Centimeter depending on country}                         scTop, {Top in Inches or Centimeter depending on country}                         scRight, {Right in Inches or Centimeter depending on country}                         scBottom, {Bottom in Inches or Centimeter depending on country}                         DPI.Value, {dpi resolution}                         Resolution, {Resolution 1,0,8,16,24}                         0, {Dither 0 or 1}                         NBright.Value,{Brightness -1000 to 1000}                         NCont.Value, {Contrast -1000 to 1000}                         nPages.Value, {Pages}                         MyPixType, {PixTypes}                         nFlags, {Flags TW_USEADF and / or TW_SHOWUI to show user interface}                         TwainDibCall, {TWAINCallBackFunction for multiple pages }                         nil, {TWainCallBackFunction for progress bar etc}                         0) {Pointer of the calling object} then begin
exit;
end;  finally    DisEn(True);    {While we are doing something in the call back we will wait}    While InCallBackCall do     Application.ProcessMessages; {do nothing}
   {Load in the temporary Jpeg file}
//PMultiImage1.ImageName:=ExtractFilePath(Application.Exename)+'TEMP.JPG';    PMultiImage1.ImageName := FindFilePath(Application.ExeName, 3, 'TEMP\TEMP.JPG')  end; end;

(****************************************************************** Zoom in image ******************************************************************) procedure TTwainForm.PMultiImage1Rubberband(Sender: TObject;   Button: TMouseButton; Shift: TShiftState; X, Y, XX, YY: Integer); begin    PMultiImage1.ZoomArea(Rect(X, Y, XX, YY)); end;
(****************************************************************** Set the scanning location ******************************************************************)
procedure TTwainForm.ScanLoc(Sender: TObject); var  S : String;  F : Real; begin     {get the string}     S:=TMaskEdit(Sender).Text;     {delete the blanks}     while Pos(' ', S) > 0 do      Delete(S, Pos(' ', S),1);     {Convert to float}     F:=StrToFloat(S);     if TMaskEdit(Sender) = TopE then        scTop :=F;     if TMaskEdit(Sender) = LeftE then        scLeft :=F;     if TMaskEdit(Sender) = RightE then        scRight :=F;     if TMaskEdit(Sender) = BotE then        scBottom :=F; end;

procedure TTwainForm.SaveBtnClick(Sender: TObject); begin end;

(****************************************************************** Close window ******************************************************************) procedure TTwainForm.ExitBtnClick(Sender: TObject); begin   Close; end;
(****************************************************************** Stretch or Stretch ratio image When stretched we set the parent to the panel else to a scroll box to enable scrollbars ******************************************************************)
procedure TTwainForm.StretchImageClick(Sender: TObject); begin     PMultiImage1.StretchRatio:= TSpeedButton(Sender).Down; end;

(****************************************************************** Disable or enable buttons ******************************************************************) procedure TTwainForm.DisEn(Enb : Boolean); begin     nPages.Enabled:=Enb;     NBright.Enabled:=Enb;     NCont.Enabled:=Enb;     SelectSourceBtn.Enabled:=Enb;     ScanImagesBtn.Enabled:=Enb;     ScanDocumentsBtn.Enabled:=Enb;     TopE.Enabled:=Enb;     LeftE.Enabled:=Enb;     RightE.Enabled:=Enb;     BotE.Enabled:=Enb;     DPI.Enabled:=Enb;     StretchImagewithRatioBtn.Enabled:=Enb;     ExitBtn.Enabled:=Enb; end;

(****************************************************************** Open the Temporary file ******************************************************************) procedure TTwainForm.OpenBtnClick(Sender: TObject); begin   {set the image directory}   //OpenDialog1.InitialDir:=ExtractFilePath(Application.Exename);   OpenDialog1.InitialDir:=FindFilePath(Application.ExeName, 3, 'Pictures\');   {execute opendialog}   if OpenDialog1.Execute then     {load image}     PMultiImage1.ImageName:= OpenDialog1.FileName;    {reset the progressbar}   ProgressBar1.Position:=0; end;


procedure TTwainForm.CheckBox4Click(Sender: TObject); begin      PMultiImage1.ResetImage;
     if CheckBox4.Checked then        CheckBox4.Caption:='Panning'      else        CheckBox4.Caption:='Zooming';
     PMultiImage1.AllowRubberBand := not CheckBox4.Checked; end;

procedure TTwainForm.Button1Click(Sender: TObject); begin      TwainCaps:=TTwainCaps.Create(Self);      TwainCaps.ShowModal;      TwainCaps.Free; end;
procedure TTwainForm.Help1Click(Sender: TObject); begin   ExecuteFile('HelpDemo.exe',               '"'+               FindFilePath(Application.ExeName, 2, 'scanindigcam.txt')+'"',               FindFilePath(Application.ExeName, 3, ''),               SW_SHOW); end;
procedure TTwainForm.Exit1Click(Sender: TObject); begin   close; end;
end.





"Gabe Covert" <wcovert@sygenex_dot_com> wrote in message news:✉FOCUSFOCUS.FFMAINSERVER.FOCUSFOCUS.COM...
> Is it possible to acquire multiple pictures from a DigiCam TWAIN dialog
> using ImageLib?  How would I go about doing that?  Is it the same process as
> a sheetfed scanner, or do I need to do something different?
>
> Gabe
>



"George Wynne" <✉nssco.com> wrote in message
news:✉FOCUSFOCUS.FFMAINSERVER.FOCUSFOCUS.COM...
> Using D5, corporate suite version 6 - demo
>
> When I run this app and scan an image, the image displays fine, but
> PMultiImage1.BTiffPages = 0.
> As a result, the TiffCounter shows "Page 1 of 0 page(s)".  Also, the Save
> button does not work, since it loops through BTiffPages.
>
> However, if I open a TIF file, BTiffPages is fine.  And if I scan an image
> after opening a TIF file, BTiffPages is also fine.
>
> Can anyone fix this?
>
> Thanks,
> George
>
>
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Sun, 19 May 2024 04:29:21 UTC
Copyright © 2009-2024
HREF Tools Corp.