⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iewia.pas

📁 ·ImageEn 2.3.0 ImageEn一组用于图像处理、查看和分析的Delphi控件。能够保存几种图像格式
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  end;

{!!
<FS>TIETransferFormat

<FM>Declaration<FC>
}
  TIETransferFormat=(ietfDefault, ietfBitmap, ietfJpeg);
{!!}

  TIEWiaEvent=(ieeNone, ieeTreeUpdated, ieeItemCreated, ieeItemDeleted);

{!!
<FS>TIEWia

<FM>Description<FN>
TIEWia class (TImageEnIO.<A TImageEnIO.WIAParams> and TImageEnMIO.<A TImageEnMIO.WIAParams> properties) allows you to set/get parameters, show dialogs and control WIA devices.

<FM>Methods<FN>

    <A TIEWia.ConnectToUsingDialog>
    <A TIEWia.UpdateItems>
    <A TIEWia.ConnectTo>
    <A TIEWia.ShowAcquireDialog>
    <A TIEWia.GetDeviceProperty>
    <A TIEWia.SetDeviceProperty>
    <A TIEWia.SetItemProperty>
    <A TIEWia.SetDevicePropertyVariant>
    <A TIEWia.SetItemPropertyVariant>
    <A TIEWia.GetItemProperty>
    <A TIEWia.GetItemPropertyAttrib>
    <A TIEWia.FillTreeView>
    <A TIEWia.GetItemThumbnail>
    <A TIEWia.DeleteItem>
    <A TIEWia.IsItemDeleted>


<FM>Properties<FN>

    <A TIEWia.DevicesInfo>
    <A TIEWia.DevicesInfoCount>
    <A TIEWia.Device>
    <A TIEWia.TakePicture>
    <A TIEWia.DeleteTakenPicture>
    <A TIEWia.SaveTransferBufferAs>
    <A TIEWia.TransferFormat>
!!}
  TIEWia = class
  private
    fIWiaDevMgr: IWiaDevMgr;
    fDevicesInfo: TList; // list of TIEWiaDeviceInfo objects
    fRoot: TIEWiaItem; // the root IWiaItem (encapsulated in TIEWiaItem)
    fCtrlParent: TComponent;
    fMultiCallBack: TIEMultiCallBack;
    fEventCallBack1: IUnknown;  // for WIA_EVENT_ITEM_CREATED event
    fEventCallBack2: IUnknown;  // for WIA_EVENT_ITEM_DELETED event
    fEventCallBack3: IUnknown;  // for WIA_EVENT_TREE_UPDATED event
    fOnProgress: TIEWiaOnProgress;
    fTakePicture:boolean;
    fDeleteTakenPicture:boolean;  // delete the item got from fTakePicture (only for cameras)
    fSaveTransferBufferAs:string;
    fTransferFormat:TIETransferFormat;
    fCurrentIndex:integer;  // index of current connected device
    fItemsTreeUpdated:TNotifyEvent;
    fLastEvent:TIEWiaEvent;
    procedure FillDevices;
    procedure FillItemChildren(parent: TIEWiaItem);
    function GetDevicesInfo(idx: integer): TIEWiaDeviceInfo;
    function GetDevicesInfoCount: integer;
    procedure EmptyDeviceInfo;
    function GetRoot: TIEWiaItem;
    function GetPage(header: PWIA_DATA_CALLBACK_HEADER; data: pointer; datalen: integer): boolean;
    procedure ConnectToDefault;
    function GetDefaultItem(var item: TIEWiaItem; LastItem:boolean): boolean;
    procedure DoItemsTreeUpdated;
  public
    ProcessingBitmap: TIEBitmap;
    ProcessingInfo: TIEWProcessingInfo;
    constructor Create(parent: TComponent);
    destructor Destroy; override;
    property DevicesInfo[idx: integer]: TIEWiaDeviceInfo read GetDevicesInfo;
    property DevicesInfoCount: integer read GetDevicesInfoCount;
    function ConnectToUsingDialog: boolean;
    property Device: TIEWiaItem read GetRoot;
    procedure UpdateItems;  // updates from Device (the root)
    function ConnectTo(idx: integer = 0): boolean;
    function ShowAcquireDialog(SystemDialog: boolean = false): boolean;
    function Transfer(item: TIEWiaItem = nil; MultiPage: boolean = false): boolean;

{!!
<FS>TIEWia.TakePicture

<FM>Declaration<FC>
property TakePicture:boolean;

<FM>Description<FN>
If true, the next acquire will take a new picture from the camera.

<FM>Demo<FN>
capture\cameragetimages
!!}
    property TakePicture:boolean read fTakePicture write fTakePicture;

{!!
<FS>TIEWia.DeleteTakenPicture

<FM>Declaration<FC>
property DeleteTakenPicture:boolean;

<FM>Description<FN>
If true, the taken picture (using <A TIEWia.TakePicture>> will be not saved in the camera memory.

<FM>Demo<FN>
capture\cameragetimages
!!}
    property DeleteTakenPicture:boolean read fDeleteTakenPicture write fDeleteTakenPicture;

    property OnProgress: TIEWiaOnProgress read fOnProgress write fOnProgress;
    property OnGetPage: TIEMultiCallBack read fMultiCallBack write fMultiCallBack;
    property OnItemsTreeUpdated:TNotifyEvent read fItemsTreeUpdated write fItemsTreeUpdated;
    property LastEvent:TIEWiaEvent read fLastEvent;
    // raw properties read/write
    function GetDeviceProperty(PropId: dword): Variant;
    function SetDeviceProperty(PropId: dword; val: integer): boolean;
    function SetItemProperty(PropId: dword; val: integer; item: TIEWiaItem): boolean;
    function SetDevicePropertyVariant(PropId: dword; val: Variant): boolean;
    function SetItemPropertyVariant(PropId: dword; val: Variant; item: TIEWiaItem): boolean;
    function GetItemProperty(PropId: dword; item: TIEWiaItem): Variant;
    procedure GetItemPropertyAttrib(PropId: dword; item: TIEWiaItem; var attrib: TIEWiaAttrib; var values: TIEWiaValues);
    procedure FillTreeView(Items:TTreeNodes; IncludeDescription:boolean);

{!!
<FS>TIEWia.SaveTransferBufferAs

<FM>Declaration<FC>
property SaveTransferBufferAs:string

<FM>Description<FN>
Specifies a filename where to transfer the raw data received from the WIA device.
This is useful when you want jpegs from a Camera, without lose data.

<FM>Demo<FN>
capture\cameragetimages
!!}
    property SaveTransferBufferAs:string read fSaveTransferBufferAs write fSaveTransferBufferAs;

{!!
<FS>TIEWia.TransferFormat

<FM>Declaration<FC>
property TransferFormat:<A TIETransferFormat>;

<FM>Description<FN>
Specifies a filename where to transfer the raw data received from the WIA device. This is useful when you want jpegs from a Camera, without lose data or a BMP from a scanner for maximum quality.

<FM>Demo<FN>
capture\cameragetimages
!!}
    property TransferFormat:TIETransferFormat read fTransferFormat write fTransferFormat;
    
    function GetItemThumbnail(item:TIEWiaItem; destBitmap:TIEBitmap):boolean;
    procedure DeleteItem(item:TIEWiaItem);
    function IsItemDeleted(item:TIEWiaItem):boolean;
  end;


implementation

uses imageenproc, bmpfilt, imageenio, jpegfilt
{$ifdef IENEWVARIANTS}
,variants
{$endif}
;

const
  CLSID_WiaDevMgr: TGUID = '{A1F4E726-8CF1-11D1-BF92-0060081ED811}';

  // commands
  WIA_CMD_TAKE_PICTURE:    TGUID =    '{af933cac-acad-11d2-a093-00c04f72dc3c}';
  WIA_CMD_SYNCHRONIZE:     TGUID =    '{9b26b7b2-acad-11d2-a093-00c04f72dc3c}';
  WIA_CMD_DELETE_ALL_ITEMS:TGUID =    '{e208c170-acad-11d2-a093-00c04f72dc3c}';
  WIA_CMD_CHANGE_DOCUMENT: TGUID =    '{04e725b0-acae-11d2-a093-00c04f72dc3c}';
  WIA_CMD_UNLOAD_DOCUMENT: TGUID =    '{1f3b3d8e-acae-11d2-a093-00c04f72dc3c}';

  // events
  WIA_EVENT_DEVICE_DISCONNECTED:TGUID='{143e4e83-6497-11d2-a231-00c04fa31809}';
  WIA_EVENT_DEVICE_CONNECTED:TGUID=   '{a28bbade-64b6-11d2-a231-00c04fa31809}';
  WIA_EVENT_ITEM_DELETED:TGUID=       '{1d22a559-e14f-11d2-b326-00c04f68ce61}';
  WIA_EVENT_ITEM_CREATED:TGUID=       '{4c8f4ef5-e14f-11d2-b326-00c04f68ce61}';
  WIA_EVENT_TREE_UPDATED:TGUID=       '{c9859b91-4ab2-4cd6-a1fc-582eec55e585}';
  WIA_EVENT_VOLUME_INSERT:TGUID=      '{9638bbfd-d1bd-11d2-b31f-00c04f68ce61}';
  WIA_EVENT_SCAN_IMAGE:TGUID=         '{a6c5a715-8c6e-11d2-977a-0000f87a926f}';
  WIA_EVENT_SCAN_PRINT_IMAGE:TGUID=   '{b441f425-8c6e-11d2-977a-0000f87a926f}';
  WIA_EVENT_SCAN_FAX_IMAGE:TGUID=     '{c00eb793-8c6e-11d2-977a-0000f87a926f}';
  WIA_EVENT_SCAN_OCR_IMAGE:TGUID=     '{9d095b89-37d6-4877-afed-62a297dc6dbe}';
  WIA_EVENT_SCAN_EMAIL_IMAGE:TGUID=   '{c686dcee-54f2-419e-9a27-2fc7f2e98f9e}';
  WIA_EVENT_SCAN_FILM_IMAGE:TGUID=    '{9b2b662c-6185-438c-b68b-e39ee25e71cb}';
  WIA_EVENT_SCAN_IMAGE2:TGUID=        '{fc4767c1-c8b3-48a2-9cfa-2e90cb3d3590}';
  WIA_EVENT_SCAN_IMAGE3:TGUID=        '{154e27be-b617-4653-acc5-0fd7bd4c65ce}';
  WIA_EVENT_SCAN_IMAGE4:TGUID=        '{a65b704a-7f3c-4447-a75d-8a26dfca1fdf}';
  WIA_EVENT_STORAGE_CREATED:TGUID=    '{353308b2-fe73-46c8-895e-fa4551ccc85a}';
  WIA_EVENT_STORAGE_DELETED:TGUID=    '{5e41e75e-9390-44c5-9a51-e47019e390cf}';
  WIA_EVENT_STI_PROXY:TGUID=          '{d711f81f-1f0d-422d-8641-927d1b93e5e5}';
  WIA_EVENT_CANCEL_IO:TGUID=          '{c860f7b8-9ccd-41ea-bbbf-4dd09c5b1795}';


  NULLGUID: TGUID = '{00000000-0000-0000-0000-000000000000}';
  CLSCTX_LOCAL_SERVER = 4;
  CLSCTX_REMOTE_SERVER = $10;
  CLSCTX_INPROC_HANDLER = 2;
  CLSCTX_INPROC_SERVER = 1;

  WIA_DEVINFO_ENUM_LOCAL = $00000010;

  PRSPEC_LPWSTR = 0;
  PRSPEC_PROPID = 1;

  WIA_SELECT_DEVICE_NODEFAULT = $00000001;
  WIA_INTENT_NONE = $00000000;
  WIA_DEVICE_DIALOG_USE_COMMON_UI = $00000004;

type

  TVarType = Word;
  TOleBool = WordBool;
  PShortInt = ^ShortInt;
  TShortIntArray = array[0..Maxint div 16] of ShortInt;
  PShortIntArray = ^TShortIntArray;
  POleBool = ^TOleBool;
  TOleBoolArray = array[0..Maxint div 16] of TOleBool;
  POleBoolArray = ^TOleBoolArray;
  TLongIntArray = array[0..Maxint div 16] of LongInt;
  PLongIntArray = ^TLongIntArray;
  TULongArray = array[0..MaxInt div 16] of ULong;
  PULongArray = ^TULongArray;
  TLargeIntegerArray = array[0..Maxint div 16] of TLargeInteger;
  PLargeIntegerArray = ^TLargeIntegerArray;

  TOleDate = Double;
  POleDate = ^TOleDate;
  TOleDateArray = array[0..maxint div 16] of TOleDate;
  POleDateArray = ^TOleDateArray;
  PCLSID = PGUID;
  PBStr = ^TBStr;
  PLPSTR = ^LPSTR;
  PLPWSTR = ^LPWSTR;

  LPWSTRArray = array[0..maxint div 16] of LPWSTR;
  PLPWSTRArray = ^LPWSTRArray;

  LPSTRArray = array[0..maxint div 16] of LPSTR;
  PLPSTRArray = ^LPSTRArray;

  TBStr = PWideChar;

  TBStrArray = array[0..maxint div 16] of TBStr;
  PBStrArray = ^TBStrArray;

  PROPSPEC = packed record
    ulKind: ULONG;
    case Integer of
      0: (propid: dword);
      1: (lpwstr: PWideChar);
  end;

  (*
  LARGE_INTEGER = packed record
    case Integer of
      0: (
        LowPart: DWORD;
        HighPart: Longint);
      1: (
        QuadPart: int64);
  end;

  ULARGE_INTEGER = packed record
    case Integer of
      0: (
        LowPart: DWORD;
        HighPart: DWORD);
      1: (
        QuadPart: int64);
  end;
  *)
  LARGE_INTEGER = packed record
        LowPart: DWORD;
        HighPart: Longint;
  end;

  ULARGE_INTEGER = packed record
        LowPart: DWORD;
        HighPart: DWORD;
  end;

  TULargeInteger = ULARGE_INTEGER;

  PULargeInteger = ^TULargeInteger;
  TULargeIntegerArray = array[0..maxint div 16] of TULargeInteger;
  PULargeIntegerArray = ^TULargeIntegerArray;
  PPropVariant = ^TPropVariant;

  TCurrencyArray = array[0..maxint div 16] of Currency;
  PCurrencyArray = ^TCurrencyArray;

  TFileTimeArray = array[0..maxint div 16] of TFileTime;
  PFileTimeArray = ^TFileTimeArray;

  TBLOB = packed record
    cbSize: Longint;
    pBlobData: Pointer;
  end;
  PClipData = ^TClipData;
  TCLIPDATA = packed record
    cbSize: Longint;
    ulClipFmt: Longint;
    pClipData: Pointer;
  end;
  TClipDataArray = array[0..maxint div 16] of TClipData;
  PClipDataArray = ^TClipDataArray;

  TGUIDArray = array[0..maxint div 32] of TGUID;
  PGUIDArray = ^TGUIDArray;

  TCAUB = packed record
    cElems: ULONG;
    pElems: PBytearray;
  end;
  TCAI = packed record
    cElems: ULONG;
    pElems: PShortIntarray;
  end;
  TCAUI = packed record
    cElems: ULONG;
    pElems: PWordarray;
  end;
  TCABOOL = packed record
    cElems: ULONG;
    pElems: POleBoolarray;
  end;
  TCAL = packed record
    cElems: ULONG;
    pElems: PLongintarray;
  end;
  TCAUL = packed record
    cElems: ULONG;
    pElems: PULONGArray;
  end;
  TCAFLT = packed record
    cElems: ULONG;
    pElems: PSinglearray;
  end;
  TCASCODE = packed record
    cElems: ULONG;
    pElems: pintegerarray;
  end;
  TCAH = packed record
    cElems: ULONG;
    pElems: PLargeIntegerArray;
  end;
  TCAUH = packed record
    cElems: ULONG;
    pElems: PULargeIntegerArray;
  end;
  TCADBL = packed record
    cElems: ULONG;
    pElems: PDoubleArray;
  end;
  TCACY = packed record
    cElems: ULONG;
    pElems: PCurrencyArray;
  end;
  TCADATE = packed record
    cElems: ULONG;
    pElems: POleDateArray;
  end;
  TCAFILETIME = packed record
    cElems: ULONG;
    pElems: PFileTimeArray;
  end;
  TCACLSID = packed record
    cElems: ULONG;
    pElems: PGUIDArray;
  end;
  TCACLIPDATA = packed record
    cElems: ULONG;
    pElems: PClipDataArray;
  end;
  TCABSTR = packed record
    cElems: ULONG;
    pElems: PBSTRArray;
  end;
  TCALPSTR = packed record
    cElems: ULONG;
    pElems: PLPSTRArray;
  end;
  TCALPWSTR = packed record
    cElems: ULONG;
    pElems: PLPWSTRArray;
  end;

  TCAPROPVARIANT = packed record
    cElems: ULONG;
    pElems: PPropVariant;
  end;

  PROPVARIANT = packed record

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -