(* ImageEn Build 7.0.0.06.2637 @ 7-4-17 14:58:42.679 *) (* Copyright (c) 1998-2017 by Carlotta Calandra. All rights reserved. Copyright (c) 2011-2017 by Xequte Software. This software comes without express or implied warranty. In no case shall the author be liable for any damage or unwanted behavior of any computer hardware and/or software. Author grants you the right to include the component in your application, whether COMMERCIAL, SHAREWARE, or FREEWARE. ImageEn, IEvolution and ImageEn ActiveX may not be included in any commercial, shareware or freeware libraries or components. www.ImageEn.com *) (* File version 1070 Doc revision 1004 *) unit imageenio; {$IFDEF FPC} {$MODE DELPHI} {$ENDIF} {$R-} {$Q-} {$I ie.inc} interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, SyncObjs, ieview, ImageEnProc, ExtCtrls, hyiedefs, iexBitmaps, Dialogs, hyieutils, iegdiplus, {$ifdef IEHASTYPES} Types, {$endif} {$ifdef IEHASUITYPES} System.UITypes, {$endif} {$IFDEF IEINCLUDEIEXACQUIRE} iexAcquire, ietwain, iexDCIM, iewia, {$ENDIF} {$IFDEF IEINCLUDEDIRECTSHOW} ieds, {$ENDIF} {$IFDEF IEINCLUDEMEDIAFOUNDATION} iemmf, {$ENDIF} {$ifdef FPC} lmetafile, {$endif} printers; const // Standard Twain sizes IETW_NONE = 0; IETW_A4LETTER = 1; IETW_B5LETTER = 2; IETW_USLETTER = 3; IETW_USLEGAL = 4; IETW_A5 = 5; IETW_B4 = 6; IETW_B6 = 7; IETW_USLEDGER = 9; IETW_USEXECUTIVE = 10; IETW_A3 = 11; IETW_B3 = 12; IETW_A6 = 13; IETW_C4 = 14; IETW_C5 = 15; IETW_C6 = 16; IETW_4A0 = 17; IETW_2A0 = 18; IETW_A0 = 19; IETW_A1 = 20; IETW_A2 = 21; IETW_A4 = IETW_A4LETTER; IETW_A7 = 22; IETW_A8 = 23; IETW_A9 = 24; IETW_A10 = 25; IETW_ISOB0 = 26; IETW_ISOB1 = 27; IETW_ISOB2 = 28; IETW_ISOB3 = IETW_B3; IETW_ISOB4 = IETW_B4; IETW_ISOB5 = 29; IETW_ISOB6 = IETW_B6; IETW_ISOB7 = 30; IETW_ISOB8 = 31; IETW_ISOB9 = 32; IETW_ISOB10 = 33; IETW_JISB0 = 34; IETW_JISB1 = 35; IETW_JISB2 = 36; IETW_JISB3 = 37; IETW_JISB4 = 38; IETW_JISB5 = IETW_B5LETTER; IETW_JISB6 = 39; IETW_JISB7 = 40; IETW_JISB8 = 41; IETW_JISB9 = 42; IETW_JISB10 = 43; IETW_C0 = 44; IETW_C1 = 45; IETW_C2 = 46; IETW_C3 = 47; IETW_C7 = 48; IETW_C8 = 49; IETW_C9 = 50; IETW_C10 = 51; IETW_USSTATEMENT = 52; IETW_BUSINESSCARD = 53; type {!! TIETextFormat Declaration TIETextFormat = (ietfPascal, ietfHex, ietfBase64, ietfASCIIArt); Description Value Description ietfPascal In this case the format is as follows: const 'FileName_Extension_Size' = nnnn; 'FileName_Extension' : array [0 .. 'FileName_Extension_Size' - 1] of byte = ( $xx,$xx ); This is useful when you want to embed the image inside a .pas file. You can load back the image by writing: ImageEnView1.IO.LoadFromBuffer(FileName_Extension, FileName_Extension_Size, fileformat); ietfHex Save the image as a sequence of hex values. Example: 0xaa, 0xbb, etc... ietfBase64 Save the image encoded with base 64 (the base of Mime64). Example: /9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYF... ietfASCIIArt Save the image as an Ascii art. We suggest you sub-sample the image before save as Ascii art. The ImageFormat field of must be ioUnknown.
!!} TIETextFormat = (ietfPascal, ietfHex, ietfBase64, ietfASCIIArt); {!! TIEAcquireBitmapEvent Declaration TIEAcquireBitmapEvent = procedure(Sender: TObject; ABitmap: ; DpiX, DpiY: Integer; var Handled: boolean) of object; Description Occurs whenever an image is acquired from a scanner. Parameter Description Sender Will be either a TImageEnIO or TImageEnMIO control ABitmap A object that contains the acquired image DpiX, DpiY Tne DPI of the acquired image Handled Setting Handled to True causes ImageEn to ignore this image (i.e. the current image won't be inserted into the control, if attached). Handled has no effect when acquiring via a TImageEnView/TImageEnIO
Note: Handled defaults to False. !!} TIEAcquireBitmapEvent = procedure(Sender: TObject; ABitmap: TIEBitmap; DpiX, DpiY: Integer; var Handled: boolean) of object; {!! TIEAfterAcquireBitmapEvent Declaration TIEAfterAcquireBitmapEvent = procedure(Sender: TObject; index: integer) of object; Description This event fired after an image has been acquired and added to the image list. index specifies the index of the new image in the attached . !!} TIEAfterAcquireBitmapEvent = procedure(Sender: TObject; index: Integer) of object; // Header used to save a jpeg inside a Stream TStreamJpegHeader = record ID: array[0..4] of AnsiChar; // ="JFIF\0" dim: integer; // length of jpeg box end; // Header used to save a PCX inside a Stream PCXSHead = record ID: array[0..4] of AnsiChar; // 'PCX2\0' dim: integer; end; // Header used to save a TIFF inside a Stream TIFFSHead = record ID: array[0..4] of AnsiChar; // 'TIFF\0' dim: integer; end; // printing properties {!! TIEVerticalPos Declaration TIEVerticalPos = (ievpTop, ievpCenter, ievpBottom); Description Value Description ievpTop Image is aligned to the top ievpCenter Image is vertically centered ievpBottom Image is aligned to the bottom
!!} TIEVerticalPos = (ievpTop, ievpCenter, ievpBottom); {!! TIEHorizontalPos Declaration TIEHorizontalPos = (iehpLeft, iehpCenter, iehpRight); Description Value Description iehpLeft Image is aligned to the left-hand side iehpCenter Image is horizontally centered iehpRight Image is aligned to the right-hand side
!!} TIEHorizontalPos = (iehpLeft, iehpCenter, iehpRight); {!! TIESize Declaration TIESize = (iesNormal, iesFitToPage, iesFitToPageStretch, iesFillPage, iesSpecifiedSize, iesMultiplePages); Description Value Description iesNormal Determine print size by the original image DPI (i.e. to create a true size copy) iesFitToPage Stretch the image to fit the page, while respecting its proportions iesFitToPageStretch Stretch the image to fit the page, ignoring the proportions iesFillPage Stretch the image to fill the entire page (respecting its proportions), cropping any edge of it so that it aligns with the orientation of the page (i.e. portions of the image may not be printed) iesSpecifiedSize Print at an absolute size specified by the SpecWidth and SpecHeight parameters iesMultiplePages Print the image over multiple pages with count specified by the SpecWidth and SpecHeight parameters
!!} TIESize = (iesNormal, iesFitToPage, iesFitToPageStretch, iesFillPage, iesSpecifiedSize, iesMultiplePages); {!! TIECreateAVIFileResult Declaration TIECreateAVIFileResult = (ieaviOK, ieaviNOCOMPRESSOR, ieaviMEMORY, ieaviUNSUPPORTED); Description Value Description ieaviOK No error ieaviNOCOMPRESSOR A suitable compressor cannot be found ieaviMEMORY There is not enough memory to complete the operation ieaviUNSUPPORTED Compression is not supported for this type of data
!!} TIECreateAVIFileResult = (ieaviOK, ieaviNOCOMPRESSOR, ieaviMEMORY, ieaviUNSUPPORTED); // occurs after preview {!! TIEIOPreviewEvent Declaration } TIEIOPreviewEvent = procedure(Sender: TObject; PreviewForm: TForm) of object; {!!} {!! TIEDoPreviewsEvent Declaration } TIEDoPreviewsEvent = procedure(Sender: TObject; var Handled: boolean) of object; {!!} {!! TIECSSource Declaration TIECSSource = (iecsScreen, iecsPrimary, iecsForegroundWindow, iecsForegroundWindowClient); Description Value Description iecsScreen Captures the entire screen (all screens on a multiple monitor system) iecsPrimary Captures the screen of the primary monitor on a multiple monitor system (or the whole screen if there is only one monitor) iecsForegroundWindow Captures the active window iecsForegroundWindowClient Captures the client area of the active window
!!} TIECSSource = (iecsScreen, iecsPrimary, iecsForegroundWindow, iecsForegroundWindowClient); {!! TIEDialogType Declaration TIEDialogType = (iedtDialog, iedtMaxi); Description iedtDialog : Show a dialog window. iedtMaxi : Show a maximized window. !!} TIEDialogType = (iedtDialog, iedtMaxi); {!! TIEDialogsMeasureUnit Declaration TIEDialogsMeasureUnit = (ieduInches, ieduCm, ieduSelectableDefInches, ieduSelectableDefCm); Description Value Description ieduInches Use inches (default) ieduCm Use centimeters (Cm) ieduSelectableDefInches Use inches but allow the user to change it ieduSelectableDefCm Use centimeters but allow the user to change it
!!} TIEDialogsMeasureUnit = (ieduInches, ieduCm, ieduSelectableDefInches, ieduSelectableDefCm); // C++Builder doesn't work if we import IEVFW in interface uses TAviStreamInfoA_Ex = record fccType: DWORD; fccHandler: DWORD; dwFlags: DWORD; // Contains AVITF_* flags dwCaps: DWORD; wPriority: WORD; wLanguage: WORD; dwScale: DWORD; dwRate: DWORD; // dwRate / dwScale == samples/second dwStart: DWORD; dwLength: DWORD; // In units above... dwInitialFrames: DWORD; dwSuggestedBufferSize: DWORD; dwQuality: DWORD; dwSampleSize: DWORD; rcFrame: TRECT; dwEditCount: DWORD; dwFormatChangeCount: DWORD; szName: array[0..63] of AnsiChar; end; TAviStreamInfoW_Ex = record fccType: DWORD; fccHandler: DWORD; dwFlags: DWORD; // Contains AVITF_* flags dwCaps: DWORD; wPriority: WORD; wLanguage: WORD; dwScale: DWORD; dwRate: DWORD; // dwRate / dwScale == samples/second dwStart: DWORD; dwLength: DWORD; // In units above... dwInitialFrames: DWORD; dwSuggestedBufferSize: DWORD; dwQuality: DWORD; dwSampleSize: DWORD; rcFrame: TRECT; dwEditCount: DWORD; dwFormatChangeCount: DWORD; szName: array[0..63] of WideChar; end; TAviStreamInfo_Ex = {$IFDEF UNICODE}TAviStreamInfoW_Ex{$ELSE}TAviStreamInfoA_Ex{$ENDIF}; {!! TIOPrintPreviewPosition Declaration } TIOPrintPreviewPosition = (ppTopLeft, ppTop, ppTopRight, ppLeft, ppCenter, ppRight, ppBottomLeft, ppBottom, ppBottomRight); {!!} {!! TIOPrintPreviewSize Declaration TIOPrintPreviewSize = (psNormal, psFitToPage, psStretchToPage, psFillPage, psSpecifiedSize, psMultiplePages); Description Aligns with
!!} TIOPrintPreviewSize = (psNormal, psFitToPage, psStretchToPage, psFillPage, psSpecifiedSize, psMultiplePages); {!! TIOPrintPreviewThumbnailStyle Declaration } TIOPrintPreviewThumbnailStyle = (ptFlat, ptSoftShadow, ptBorder); {!!} {$IFDEF IEINCLUDEPRINTDIALOGS} {!! TIOPrintPreviewParams Description This class provides access to the properties of the Print Preview dialog. Methods and Properties Storage Handling Settings TImageEnMIO.DoPrintPreviewDialog Only !!} TIOPrintPreviewParams = class private fMarginTop: Double; fMarginLeft: Double; fMarginRight: Double; fMarginBottom: Double; fPosition: TIOPrintPreviewPosition; fSize: TIOPrintPreviewSize; fWidth: Double; // <=0: autocalculated fHeight: Double; // <=0: autocalculated fGamma: Double; fPrintSelected : Boolean; fPrintThumbnails : Boolean; fThumbnailColumns : Integer; fThumbnailRows : Integer; fThumbnailSpacing : Double; fThumbnailStyle : TIOPrintPreviewThumbnailStyle; fThumbnailShowText : Boolean; fDlgWidth : Integer; fDlgHeight : Integer; public constructor Create; {!! TIOPrintPreviewParams.MarginTop Declaration property MarginTop: Double; Description The top margin (unprintable area) of the printed page. !!} property MarginTop: Double read fMarginTop write fMarginTop; {!! TIOPrintPreviewParams.MarginLeft Declaration property MarginLeft: Double; Description The left margin (unprintable area) of the printed page. !!} property MarginLeft: Double read fMarginLeft write fMarginLeft; {!! TIOPrintPreviewParams.MarginRight Declaration property MarginRight: Double; Description The right margin (unprintable area) of the printed page. !!} property MarginRight: Double read fMarginRight write fMarginRight; {!! TIOPrintPreviewParams.MarginBottom Declaration property MarginBottom: Double; Description The bottom margin (unprintable area) of the printed page. !!} property MarginBottom: Double read fMarginBottom write fMarginBottom; {!! TIOPrintPreviewParams.Position Declaration property Position: ; Description The alignment of the image on the printed page. !!} property Position: TIOPrintPreviewPosition read fPosition write fPosition; {!! TIOPrintPreviewParams.Size Declaration property Size: ; Description The size of the image on the printed page. !!} property Size: TIOPrintPreviewSize read fSize write fSize; {!! TIOPrintPreviewParams.Width Declaration property Width: Double; Description Width of the printed image when = psSpecifiedSize (in inches or CM depending on ). Number of pages across when = psMultiplePages. !!} property Width: Double read fWidth write fWidth; {!! TIOPrintPreviewParams.Height Declaration property Height: Double; Description Height of the printed image when = psSpecifiedSize (in inches or CM depending on ). Number of pages down when = psMultiplePages. !!} property Height: Double read fHeight write fHeight; {!! TIOPrintPreviewParams.Gamma Declaration property Gamma: Double; Description Gamma value. !!} property Gamma: Double read fGamma write fGamma; {!! TIOPrintPreviewParams.PrintSelected Declaration property PrintSelected: Boolean; Description Default to printing the images selected in the associated instead of printing all images (TImageEnMIO. only). Default: False !!} property PrintSelected: Boolean read fPrintSelected write fPrintSelected; {!! TIOPrintPreviewParams.PrintThumbnails Declaration property PrintThumbnails: Boolean; Description Default to printing of thumbnails (TImageEnMIO. only). Default: False !!} property PrintThumbnails: Boolean read fPrintThumbnails write fPrintThumbnails; {!! TIOPrintPreviewParams.ThumbnailColumns Declaration property ThumbnailColumns: Integer; Description Number of thumbnail columns per page (TImageEnMIO. only) !!} property ThumbnailColumns: Integer read fThumbnailColumns write fThumbnailColumns; {!! TIOPrintPreviewParams.ThumbnailRows Declaration property ThumbnailRows: Integer; Description Number of thumbnail rows per page (TImageEnMIO. only) !!} property ThumbnailRows: Integer read fThumbnailRows write fThumbnailRows; {!! TIOPrintPreviewParams.ThumbnailSpacing Declaration property ThumbnailSpacing : Double; Description Spacing between each thumbnail in inches or CM depending on (TImageEnMIO. only) !!} property ThumbnailSpacing : Double read fThumbnailSpacing write fThumbnailSpacing; {!! TIOPrintPreviewParams.ThumbnailStyle Declaration property ThumbnailStyle: ; Description Style of printed thumbnails (TImageEnMIO.DoPrintPreviewDialog only) !!} property ThumbnailStyle: TIOPrintPreviewThumbnailStyle read fThumbnailStyle write fThumbnailStyle; {!! TIOPrintPreviewParams.ThumbnailShowText Declaration property ThumbnailShowText: Boolean; Description Whether the caption from items in a TImageEnMView is included when printing thumbnails (TImageEnMIO. only) !!} property ThumbnailShowText: Boolean read fThumbnailShowText write fThumbnailShowText; {!! TIOPrintPreviewParams.DlgWidth Declaration property DlgWidth : Integer; Description The width of the Preview dialog in pixels or zero for the default size (TImageEnMIO. only) !!} property DlgWidth : Integer read fDlgWidth write fDlgWidth; {!! TIOPrintPreviewParams.DlgHeight Declaration property DlgHeight : Integer; Description The Height of the Preview dialog in pixels or zero for the default size (TImageEnMIO. only) !!} property DlgHeight : Integer read fDlgHeight write fDlgHeight; procedure SaveToFile(const FileName: WideString); procedure LoadFromFile(const FileName: WideString); procedure SaveToStream(Stream: TStream); procedure LoadFromStream(Stream: TStream); procedure SetProperty(Prop, Value: WideString); function GetProperty(const Prop: WideString): WideString; end; {$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////// // TImageEnIO {!! TImageEnIO.TIEIOSeekDestination Declaration TIEIOSeekDestination = (ieioSeekFirst, ieioSeekPrior, ieioSeekNext, ieioSeekLast); Description Parameter Description ieioSeekFirst Go to first page ieioSeekPrior Go to previous page (or first page) ieioSeekNext Go to next page (or last page) ieioSeekLast Go to last page
!!} TIEIOSeekDestination = (ieioSeekFirst, ieioSeekPrior, ieioSeekNext, ieioSeekLast); {!! TImageEnIO Description TImageEnIO provides input/output support to ImageEn: - Loading and saving images - Access to image properties and meta-data - Acquisition of images from cameras and scanners - Printing - DirectShow functions for multimedia support See also:
, which is made to work with images containing multiple frames (e.g. animated GIFs) Generally you will not add a TImageEnIO component directly to your project. It is accessed via the following methods: 1. Using the property of a or ImageEnView1.IO.LoadFromFile('C:\MyImage.jpeg'); ImageEnView1.IO.DoPrintPreviewDialog; 2. Attached to a TBitmap or in code MyBitmap := TBitmap.create; AnImageEnIO := TImageEnIO.CreateFromBitmap(MyBitmap); AnImageEnIO.LoadFromFile('C:\input.jpg'); ... AnImageEnIO.Free; MyBitmap.Free; 3. Attached to a TImage Note: In this case a TImageEnIO would be added to the form and the set appropriately. Notes - Ensure you do not call any TImageEnIO methods before it is actually attached to an image container (, , etc) - Do not attach TImageEnIO to a component. Only a can be attached to a component. Methods and Properties Connected Component Generic Input/Output Image Acquisition (Twain/WIA) Aynchronous input/output DirectShow capture Dialogs Printing IEN (ImageEn native image format with layers) JPEG JPEG 2000 GIF Adobe PSD Microsoft HD Photos (HDP) TIFF BMP PNG Cursors (CUR) ICO PCX DCX (Multipage PCX) Meta Files (WMF, EMF) SVG (Scalable Vector Graphics) Targa (TGA) PXM (PPM, PBM, PGM) AVI Videos WBMP PostScript (PS) Adobe PDF Raw Camera Files Media Files (AVI, MPEG, WMV..) BmpRaw (a true "raw" format, not the same as a digital camera Raw file) DICOM Medical Imaging Format Events !!} {$ifdef IEHASPLATFORMATTRIBUTE} [ComponentPlatformsAttribute(pidWin32 or pidWin64)] {$endif} TImageEnIO = class(TComponent) private fBitmap: TBitmap; // refers to the bitmap (if fImageEnView is valid then it is FImageEnView.bitmap) fIEBitmap: TIEBitmap; // encapsulates fBitmap if SetBitmap, SetAttachedBitmap, SetAttachedImageEn, SetTImage are called fIEBitmapCreated: boolean; // true is fIEBitmap is created by TImageEnIO fImageEnView: TIEView; // refers to TIEView (fbitmap=fimageenview.bitmap) fImageEnViewBitmapChangeHandle: Pointer; // bitmap change handle (nil=none) fTImage: TImage; // refers to TImage fBackground: TColor; // valid only if fImageEnview = nil fPreviewsParams: TIOPreviewsParams; fSimplifiedParamsDialogs: boolean; fOnDoPreviews: TIEDoPreviewsEvent; fChangeBackground: boolean; // if true change the Background property using the loaded image background {$ifdef IEINCLUDEIEXACQUIRE} fAcquireParams : TIEAcquireParams; fTwainParams: TIETwainParams; {$endif} {$IFDEF IEINCLUDEWPD} fDCIMParams : TIEDcimAcquire; {$endif} fStreamHeaders: boolean; // enable/disable load/save stream headers fPreviewFont: TFont; fPreviewFontEnabled: Boolean; fOnIOPreview: TIEIOPreviewEvent; fDialogsMeasureUnit: TIEDialogsMeasureUnit; fAutoAdjustDPI: boolean; fFilteredAdjustDPI: boolean; fAVI_avf: pointer; // PAVIFILE fAVI_avs: pointer; // PAVISTREAM fAVI_avs1: pointer; // PAVISTREAM fAVI_gf: pointer; // PGETFRAME fAVI_psi: TAviStreamInfoW_Ex; fAVI_popts: pointer; // PAVICOMPRESSOPTIONS fAVI_idx: integer; {$ifdef IEINCLUDEDIRECTSHOW} fOpenMediaFile: TIEDirectShow; // open media file fOpenMediaFileRate: Double; fOpenMediaFileMul: Integer; {$endif} fPS_handle: pointer; fPS_stream: TIEWideFileStream; fPDF_handle: pointer; fPDF_stream: TIEWideFileStream; fAsyncThreads: TList; // Count > 0 is one or more threads are running fAsyncThreadsFinishEvent: THandle; fAsyncThreadsCS: TCriticalSection; // protect fAsyncThreads access fAsyncMode: boolean; // true if we need async mode fPrintingFilterOnSubsampling: TResampleFilter; // Twain modeless fgrec: pointer; // WIA {$IFDEF IEINCLUDEIEXACQUIRE} fWIA: TIEWia; {$ENDIF} // DirectShow {$IFDEF IEINCLUDEDIRECTSHOW} fDShow: TIEDirectShow; {$ENDIF} // Media Foundation Grabber {$IFDEF IEINCLUDEMEDIAFOUNDATION} fMediaFoundationSourceReader: TIEMediaFoundationSourceReader; {$ENDIF} // fDefaultDitherMethod: TIEDitherMethod; fResetPrinter: boolean; {$IFDEF IEINCLUDEPRINTDIALOGS} fPrintPreviewParams: TIOPrintPreviewParams; {$ENDIF} // function IsInsideAsyncThreads: Boolean; procedure SetAttachedBitmap(atBitmap: TBitmap); procedure SetAttachedImageEn(atImageEn: TIEView); function GetReBackground: TColor; procedure SetReBackground(v: TColor); procedure SetPreviewFont(f: TFont); procedure SetPreviewFontEnabled(Value: Boolean); procedure SetTImage(v: TImage); procedure SetIOPreviewParams(v: TIOPreviewsParams); function GetIOPreviewParams: TIOPreviewsParams; procedure AdjustDPI; function GetAsyncRunning: integer; function GetThreadsCount: integer; procedure SetDefaultDitherMethod(Value: TIEDitherMethod); {$IFDEF IEINCLUDEIEXACQUIRE} function WiaOnProgress(Percentage: integer): boolean; {$ENDIF} procedure SetPrintLogFile(v: String); function GetPrintLogFile: String; procedure UpdateAPP138BimResolution; procedure ParamsFromMetaFile(stream: TStream); function GetImageEnVersion: String; procedure SetImageEnVersion(Value: String); procedure SetAborting(Value: Boolean); function GetParams: TIOParams; function ParamsFromFileOrStream(const FileName: WideString; Stream: TStream; Format: TIOFileType): Boolean; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-08) function GetProxyAddress: WideString; function GetProxyUser: WideString; function GetProxyPassword: WideString; procedure SetProxyAddress(Value: WideString); procedure SetProxyUser(Value: WideString); procedure SetProxyPassword(Value: WideString); {$ENDIF} procedure CheckHaveValidBitmap(); procedure ParamsFromStreamIEN(Stream: TStream; LoadThumbnail: Boolean = False); procedure GeneratePrintBitmap(PrintAnnotations, PrintLayers: Boolean); procedure ResetModified(AllLayers: Boolean = False); protected fAborting: boolean; fOnIntProgress: TIEProgressEvent; // internal progress event, always assigned to DoIntProgress fOnProgress: TIEProgressEvent; fOnFinishWork: TNotifyEvent; fOnAcquireBitmap: TIEAcquireBitmapEvent; fOnAcquireClose: TNotifyEvent; procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure OnBitmapChange(Sender: TObject; destroying: boolean); {$IFDEF IEINCLUDEJPEG2000} function LoadFromStreamJ2000(Stream: TStream): Boolean; procedure SaveToStreamJ2000(Stream: TStream; format: integer); {$ENDIF} // IEINCLUDEJPEG2000 procedure SetBitmap(bmp: TBitmap); procedure SetIEBitmap(bmp: TIEBitmap); procedure SetAttachedIEBitmap(bmp: TIEBitmap); procedure TWMultiCallBack(Bitmap: TIEBitmap; var IOParams: TObject; ImDpiX, ImDpiY: integer); virtual; procedure TWCloseCallBack; virtual; procedure DoAcquireBitmap(ABitmap: TIEBitmap; ImDpiX, ImDpiY: integer; var Handled: boolean); dynamic; procedure DoFinishWork; virtual; function GetBitmap: TBitmap; virtual; function MakeConsistentBitmap(allowedFormats: TIEPixelFormatSet): boolean; {$IFDEF IEINCLUDEIEXACQUIRE} function GetWIAParams: TIEWia; virtual; {$ENDIF} {$IFDEF IEINCLUDEDIRECTSHOW} function GetDShowParams: TIEDirectShow; virtual; {$ENDIF} {$IFDEF IEINCLUDEMEDIAFOUNDATION} function GetMediaFoundationSourceReader(): TIEMediaFoundationSourceReader; {$ENDIF} function SyncLoadFromStreamGIF(Stream: TStream): integer; function SyncLoadFromStreamPCX(Stream: TStream; streamhead: boolean) : Boolean; function SyncLoadFromStreamDCX(Stream: TStream) : Boolean; function SyncLoadFromStreamTIFF(Stream: TStream; streamhead: boolean): integer; function SyncLoadFromStreamBMP(Stream: TStream) : Boolean; procedure SyncSaveToStreamJpeg(Stream: TStream; streamhead: boolean); procedure SyncSaveToStreamPS(Stream: TStream); {$ifdef IEINCLUDEPDFWRITING} procedure SyncSaveToStreamPDF(Stream: TStream); {$endif} {$ifdef IEINCLUDEDICOM} procedure SyncSaveToStreamDICOM(Stream: TStream); {$endif} procedure SyncSaveToStreamBMP(Stream: TStream); procedure SyncSaveToStreamDCX(Stream: TStream); {$ifdef IEINCLUDEPSD} function SyncLoadFromStreamPSD(Stream: TStream) : Boolean; {$endif} function SyncLoadFromStreamCUR(Stream: TStream) : Boolean; function SyncLoadFromStreamICO(Stream: TStream) : Boolean; {$ifdef IEINCLUDEWIC} function SyncLoadFromStreamHDP(Stream: TStream) : Boolean; {$endif} {$ifdef IEINCLUDERAWFORMATS} function SyncLoadFromStreamRAW(Stream: TStream) : Boolean; {$endif} function SyncLoadFromStreamBMPRAW(Stream: TStream) : Boolean; procedure SyncSaveToStreamBMPRAW(Stream: TStream); function SyncLoadFromStreamTGA(Stream: TStream) : Boolean; function SyncLoadFromStreamPNG(Stream: TStream) : Boolean; function SyncLoadFromStreamPXM(Stream: TStream) : Boolean; function SyncLoadFromStreamWBMP(Stream: TStream) : Boolean; function SyncLoadFromStreamJPEG(Stream: TStream; bCheckHeader: Boolean) : Boolean; {$ifdef IEINCLUDEDICOM} function SyncLoadFromStreamDICOM(Stream: TStream) : Boolean; {$endif} procedure CheckDPI; procedure SetNativePixelFormat(value: Boolean); function GetNativePixelFormat: Boolean; procedure DoIntProgress(Sender: TObject; per: integer); virtual; {$ifdef IEINCLUDEPSD} procedure SyncSaveToStreamPSD(Stream: TStream); {$endif} {$ifdef IEINCLUDEWIC} procedure SyncSaveToStreamHDP(Stream: TStream); {$endif} function LoadVectFile(const fileName: WideString; ft: TIOFileType): Boolean; function LoadVectStream(Stream: TStream; ft: TIOFileType): Boolean; {$ifdef IEINCLUDEIEXACQUIRE} function GetSelectedAcquireSource : TIEAcquireSource; {$endif} public fParams: TIOParams; fPrintBitmap: TIEBitmap; // When using Print preview this is the actual image to print constructor Create(Owner: TComponent); override; constructor CreateFromBitmap(Bitmap: TIEBitmap); overload; constructor CreateFromBitmap(Bitmap: TBitmap); overload; destructor Destroy; override; property AttachedBitmap: TBitmap read fBitmap write SetAttachedBitmap; property AttachedIEBitmap: TIEBitmap read fIEBitmap write SetAttachedIEBitmap; procedure Update(); procedure SyncGetHandle; {!! TImageEnIO.ChangeBackground Declaration property ChangeBackground: Boolean; Description When set to True, the background color of the attached will automatically be set to to the image background color. Default: False Note: Not all file formats contains background color information. !!} property ChangeBackground: boolean read fChangeBackground write fChangeBackground; property ThreadsCount: integer read GetThreadsCount; property DefaultDitherMethod: TIEDitherMethod read fDefaultDitherMethod write SetDefaultDitherMethod; {$IFDEF IEINCLUDEDIALOGIO} function DoPreviews(pp: TPreviewParams = [ppAll]): boolean; virtual; {$ENDIF} // IEINCLUDEDIALOGIO property Bitmap: TBitmap read GetBitmap write SetBitmap; property IEBitmap: TIEBitmap read fIEBitmap write SetIEBitmap; {!! TImageEnIO.Params Declaration property Params: ; Description Provides access to the parameters and meta-data of the current image as a object. This object contains many format specific properties, such as bits per sample, type of compression, embedded text data, etc. It is filled automatically when loading images or manually using . The properties can also be set or modified when saving files. Example // Sets color-mapped 256 colors ImageEnView1.IO.Params.BitsPerSample := 8; ImageEnView1.IO.Params.SamplesPerPixel := 1; // Sets JPEG quality of 90% ImageEnView1.IO.Params.JPEG_Quality := 90; ImageEnView1.IO.SaveToFile('D:\output.jpg'); !!} property Params: TIOParams read GetParams; procedure AssignParams(Source: TObject); procedure RecreatedTImageEnViewHandle; {$ifdef IEINCLUDERESOURCEEXTRACTOR} procedure LoadFromResource(const ModulePath: WideString; const ResourceType: String; const ResourceName: String; Format: TIOFileType); {$endif} // IEN function LoadFromFileIEN(const FileName: WideString; Append: Boolean = False): Boolean; function LoadFromStreamIEN(Stream: TStream; Append: Boolean = False): Boolean; procedure SaveToStreamIEN(Stream: TStream); procedure SaveToFileIEN(const FileName: WideString); // SVG procedure SaveToStreamSVG(Stream: TStream); procedure SaveToFileSVG(const FileName: WideString); // JPEG procedure SaveToFileJpeg(const FileName: WideString); function LoadFromFileJpeg(const FileName: WideString): Boolean; procedure SaveToStreamJpeg(Stream: TStream); function LoadFromStreamJpeg(Stream: TStream): Boolean; function InjectJpegIPTC(const FileName: WideString): boolean; function InjectJpegIPTCStream(InputStream, OutputStream: TStream): boolean; function InjectJpegEXIF(const FileName: WideString): boolean; function InjectJpegEXIFStream(InputStream, OutputStream: TStream): boolean; // DCX function LoadFromFileDCX(const FileName: WideString): Boolean; function LoadFromStreamDCX(Stream: TStream): Boolean; procedure SaveToStreamDCX(Stream: TStream); procedure SaveToFileDCX(const FileName: WideString); procedure InsertToFileDCX(const FileName: WideString); // JPEG2000 {$IFDEF IEINCLUDEJPEG2000} function LoadFromFileJP2(const FileName: WideString): Boolean; function LoadFromFileJ2K(const FileName: WideString): Boolean; function LoadFromStreamJP2(Stream: TStream): Boolean; function LoadFromStreamJ2K(Stream: TStream): Boolean; procedure SaveToStreamJP2(Stream: TStream); procedure SaveToStreamJ2K(stream: TStream); procedure SaveToFileJP2(const FileName: WideString); procedure SaveToFileJ2K(const FileName: WideString); {$ENDIF} // IEINCLUDEJPEG2000 // GIF function LoadFromFileGIF(const FileName: WideString): integer; procedure SaveToFileGIF(const FileName: WideString); function InsertToFileGIF(const FileName: WideString): integer; function LoadFromStreamGIF(Stream: TStream): integer; procedure SaveToStreamGIF(Stream: TStream); function ReplaceFileGIF(const FileName: WideString): integer; // PCX procedure SaveToStreamPCX(Stream: TStream); function LoadFromStreamPCX(Stream: TStream): Boolean; procedure SaveToFilePCX(const FileName: WideString); function LoadFromFilePCX(const FileName: WideString): Boolean; // TIFF function LoadFromStreamTIFF(Stream: TStream): integer; procedure SaveToStreamTIFF(Stream: TStream); function LoadFromFileTIFF(const FileName: WideString): integer; procedure SaveToFileTIFF(const FileName: WideString); function InsertToFileTIFF(const FileName: WideString): integer; function InsertToStreamTIFF(Stream: TStream): integer; function ReplaceFileTIFF(const FileName: WideString): integer; function ReplaceStreamTIFF(Stream: TStream): integer; {$ifdef IEINCLUDETIFFHANDLER} function InjectTIFFEXIF(const FileName: WideString; pageIndex: Integer = 0): boolean; overload; function InjectTIFFEXIF(const InputFileName, OutputFileName: WideString; pageIndex: Integer = 0): boolean; overload; function InjectTIFFEXIF(InputStream, OutputStream: TStream; pageIndex: Integer = 0): boolean; overload; {$endif} // BMP procedure SaveToStreamBMP(Stream: TStream); function LoadFromStreamBMP(Stream: TStream): Boolean; procedure SaveToFileBMP(const FileName: WideString); function LoadFromFileBMP(const FileName: WideString): Boolean; // ICO function LoadFromFileICO(const FileName: WideString): Boolean; function LoadFromStreamICO(Stream: TStream): Boolean; procedure SaveToStreamICO(Stream: TStream); procedure SaveToFileICO(const FileName: WideString); // CUR function LoadFromFileCUR(const FileName: WideString): Boolean; function LoadFromStreamCUR(Stream: TStream): Boolean; // PNG {$IFDEF IEINCLUDEPNG} function LoadFromFilePNG(const FileName: WideString): Boolean; function LoadFromStreamPNG(Stream: TStream): Boolean; procedure SaveToFilePNG(const FileName: WideString); procedure SaveToStreamPNG(Stream: TStream); {$ENDIF} {$ifdef IEINCLUDEDICOM} // DICOM function LoadFromFileDICOM(const FileName: WideString): Boolean; function LoadFromStreamDICOM(Stream: TStream): Boolean; procedure SaveToStreamDICOM(Stream: TStream); procedure SaveToFileDICOM(const FileName: WideString); {$endif} // TGA function LoadFromFileTGA(const FileName: WideString): Boolean; function LoadFromStreamTGA(Stream: TStream): Boolean; procedure SaveToFileTGA(const FileName: WideString); procedure SaveToStreamTGA(Stream: TStream); // METAFILE (WMF, EMF) function ImportMetafile(const FileName: WideString; Width: Integer = -1; Height: Integer = -1; WithAlpha: boolean = True): Boolean; overload; function ImportMetafile(Stream: TStream; Width: Integer = -1; Height: Integer = -1; WithAlpha: boolean = True): Boolean; overload; function ImportMetafile(meta: TMetafile; Width: Integer = -1; Height: Integer = -1; WithAlpha: boolean = True): Boolean; overload; function ImportMetafile(meta: TIEMetafile; Width: Integer = -1; Height: Integer = -1; WithAlpha: boolean = True): Boolean; overload; procedure MergeMetafile(const FileName: WideString; x, y: Integer; Width: Integer = -1; Height: Integer = -1); // PXM, PBM, PGM, PPM function LoadFromFilePXM(const FileName: WideString): Boolean; function LoadFromStreamPXM(Stream: TStream): Boolean; procedure SaveToFilePXM(const FileName: WideString); procedure SaveToStreamPXM(Stream: TStream); // AVI function OpenAVIFile(const FileName: WideString): integer; procedure CloseAVIFile; function LoadFromAVI(FrameIndex: integer): Boolean; function CreateAVIFile(const FileName: WideString; rate: Double = 15.0; const codec: AnsiString='DIB '): TIECreateAVIFileResult; procedure SaveToAVI; function IsOpenAVI: Boolean; // Media File {$ifdef IEINCLUDEDIRECTSHOW} function OpenMediaFile(const FileName: WideString): Integer; procedure CloseMediaFile; procedure LoadFromMediaFile(FrameIndex: Integer); function IsOpenMediaFile: Boolean; {$endif} // WBMP function LoadFromFileWBMP(const FileName: WideString): Boolean; function LoadFromStreamWBMP(Stream: TStream): Boolean; procedure SaveToFileWBMP(const FileName: WideString); procedure SaveToStreamWBMP(Stream: TStream); // PostScript (PS) procedure CreatePSFile(const FileName: WideString); procedure SaveToPS; procedure ClosePSFile; procedure SaveToStreamPS(Stream: TStream); procedure SaveToFilePS(const FileName: WideString); // PDF {$ifdef IEINCLUDEPDFWRITING} procedure CreatePDFFile(const FileName: WideString); procedure SaveToPDF; procedure ClosePDFFile; procedure SaveToStreamPDF(Stream: TStream); procedure SaveToFilePDF(const FileName: WideString); {$endif} // RAW {$ifdef IEINCLUDERAWFORMATS} function LoadFromStreamRAW(Stream: TStream): Boolean; function LoadFromFileRAW(const FileName: WideString): Boolean; function LoadJpegFromFileCRW(const FileName: WideString): Boolean; {$endif} // Real RAW function LoadFromStreamBMPRAW(Stream: TStream): Boolean; function LoadFromFileBMPRAW(const FileName: WideString): Boolean; procedure SaveToStreamBMPRAW(Stream: TStream); procedure SaveToFileBMPRAW(const FileName: WideString); // PSD {$ifdef IEINCLUDEPSD} function LoadFromStreamPSD(Stream: TStream): Boolean; function LoadFromFilePSD(const FileName: WideString): Boolean; procedure SaveToStreamPSD(Stream: TStream); procedure SaveToFilePSD(const FileName: WideString); {$endif} // HDP {$ifdef IEINCLUDEWIC} function LoadFromStreamHDP(Stream: TStream): Boolean; function LoadFromFileHDP(const FileName: WideString): Boolean; procedure SaveToStreamHDP(Stream: TStream); procedure SaveToFileHDP(const FileName: WideString); {$endif} // GENERAL function LoadFromFile(const FileName: WideString; FileFormat: TIOFileType): Boolean; overload; dynamic; function LoadFromFile(const FileName: WideString; bCheckUnknown: Boolean = True): Boolean; overload; dynamic; function LoadFromFileAuto(const FileName: WideString): Boolean; dynamic; procedure SaveToFile(const FileName: WideString; ImageFormat: TIOFileType = -1); dynamic; procedure SaveToText(const FileName: WideString; ImageFormat: TIOFileType = -1; TextFormat: TIETextFormat = ietfASCIIArt); overload; dynamic; procedure SaveToText(Stream: TStream; ImageFormat: TIOFileType = -1; TextFormat: TIETextFormat = ietfASCIIArt); overload; dynamic; procedure LoadFromText(const FileName: WideString; TextFormat: TIETextFormat = ietfBase64); overload; procedure LoadFromText(Stream: TStream; TextFormat: TIETextFormat = ietfBase64); overload; procedure LoadFromBuffer(Buffer: Pointer; BufferSize: Integer; Format: TIOFileType = ioUnknown); dynamic; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-16) function LoadFromFileFormat(const FileName: WideString; FileFormat: TIOFileType): Boolean; dynamic; {$ifdef IEWarningForDeprecated} deprecated {$ifdef IESupportDeprecatedDescription} 'Use LoadFromFile instead - http://imageen.com/help/Compatibility.html' {$endif}; {$endif} function LoadFromStreamFormat(Stream: TStream; FileFormat: TIOFileType): Boolean; dynamic; {$ifdef IEWarningForDeprecated} deprecated {$ifdef IESupportDeprecatedDescription} 'Use LoadFromStream instead - http://imageen.com/help/Compatibility.html' {$endif}; {$endif} {$endif} {!! TImageEnIO.Aborting Declaration property Aborting: Boolean; Description During an operation such as loading or saving, setting Aborting to true will halt the current process. If set to True while loading, the loaded image will be truncated (i.e. only a portion of the image is loaded). If set to True while saving, the file will be closed and truncated (i.e. it will be unreadable and should be deleted). Aborting can also be read after loading or saving to determine if an abort has occured. Load Error Example MyImageEnMView.LoadFromFileGIF('C:\MyGif.gif'); if MyImageEnMView.Aborting then ShowMessage('GIF Load Error!'); Which is the same as: if MyImageEnMView.LoadFromFileGIF('C:\MyGif.gif') = False then ShowMessage('GIF Load Error!'); Abort Loading Example // Begin to load image procedure TForm1.btnLoadClick(Sender: TObject); begin ImageEnView1.IO.LoadFromFile('C:\xyx.bmp'); end; // Progress of load procedure TForm1.ImageEnIO1Progress(Sender: TObject; per: Integer); begin ProgressBar1.Position := per; Application.ProcessMessages; // <- important! end; // STOP! button procedure TForm1.btnStopClick(Sender: TObject); begin // Cancel loading ImageEnView1.IO.Aborting := True; end; !!} property Aborting: boolean read fAborting write SetAborting; function ParamsFromFile(const FileName: WideString; Format: TIOFileType): Boolean; overload; dynamic; function ParamsFromFile(const FileName: WideString; bUseExtension: Boolean = False): Boolean; overload; dynamic; function ParamsFromStream(Stream: TStream; Format: TIOFileType = ioUnknown): Boolean; dynamic; function ParamsFromBuffer(Buffer: Pointer; BufferSize: Integer; Format: TIOFileType = ioUnknown): Boolean; dynamic; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-16) function ParamsFromFileFormat(const FileName: WideString; Format: TIOFileType): Boolean; dynamic; {$ifdef IEWarningForDeprecated} deprecated {$ifdef IESupportDeprecatedDescription} 'Use ParamsFromFile instead - http://imageen.com/help/Compatibility.html' {$endif}; {$endif} function ParamsFromStreamFormat(Stream: TStream; Format: TIOFileType): Boolean; dynamic; {$ifdef IEWarningForDeprecated} deprecated {$ifdef IESupportDeprecatedDescription} 'Use ParamsFromStream instead - http://imageen.com/help/Compatibility.html' {$endif}; {$endif} {$ENDIF} function LoadFromStream(Stream: TStream; FileFormat: TIOFileType = ioUnknown): Boolean; dynamic; {$IFDEF VIDEO_THUMBNAILS} function LoadThumbnailFromExplorer(const FileName : WideString; iDesiredWidth : Integer = 120; iDesiredHeight : Integer = 120) : Boolean; {$ENDIF} procedure SaveToStream(Stream: TStream; FileType: TIOFileType); dynamic; function Seek(Destination: TIEIOSeekDestination; FileName: WideString = ''): Integer; {$IFDEF IEINCLUDEOPENSAVEDIALOGS} function ExecuteOpenDialog(const InitialDir : WideString = ''; const InitialFileName : WideString = ''; AlwaysAnimate : boolean = False; FilterIndex: Integer = 0; const ExtendedFilters : WideString = ''; const Title : WideString = ''; const Filter : WideString = ''; DefaultFilter : TIOFileType = -1; LimitToFileType : TIOFileType = -1) : WideString; overload; function ExecuteOpenDialog(const Title : WideString; DefaultFilter : TIOFileType; LimitToFileType : TIOFileType = -1; AlwaysAnimate : boolean = False) : WideString; overload; function ExecuteSaveDialog(const InitialDir : WideString = ''; const InitialFileName : WideString = ''; AlwaysAnimate : boolean = False; FilterIndex: Integer = 0; const ExtendedFilters : WideString = ''; const Title : WideString = ''; const Filter : WideString = ''; DefaultFilter : TIOFileType = -1; LimitToFileType : TIOFileType = -1) : WideString; overload; function ExecuteSaveDialog(const Title : WideString; DefaultFilter : TIOFileType; LimitToFileType : TIOFileType = -1; AlwaysAnimate : boolean = False) : WideString; overload; {$ENDIF} // IEINCLUDEOPENSAVEDIALOGS procedure CaptureFromScreen(Source: TIECSSource = iecsScreen; MouseCursor: TCursor = -1); function LoadFromURL(const URL: WideString): Boolean; // TWAIN SCANNERS {$IFDEF IEINCLUDEIEXACQUIRE} function Acquire(bResetParams : Boolean = False) : boolean; function SelectAcquireSource(Apis : TIEAcquireApis = [ieaTwain, ieaWIA]): boolean; function SetAcquireSource(Api: TIEAcquireApi; Location : Variant) : boolean; property SelectedAcquireSource : TIEAcquireSource read GetSelectedAcquireSource; function TwainAcquireOpen: boolean; procedure TwainAcquireClose; function AcquireOpen: boolean; procedure AcquireClose; // Internal use only procedure InitializeAcquireSource(bIncludeWIA : Boolean); {$ENDIF} // IEINCLUDEIEXACQUIRE // ASYNC WORKS property AsyncRunning: integer read GetAsyncRunning; {!! TImageEnIO.AsyncMode Declaration property AsyncMode: Boolean; Description Set to True to enable asynchronous input/output operations. When asynchronous mode is enabled, each input/output method creates a new thread to executes the task then returns without waiting for the task to complete. Note: Applicable only when TImageEnIO is attached to a object. Demo Demos\InputOutput\Preload\Preload.dpr Example // multithread saving Var Bmp: TIEBitmap; Io: TImageEnIO; Begin Bmp:= TIEBitmap.Create; Io := TImageEnIO.CreateFromBitmap(bmp); Io.LoadFromFile('C:\input.bmp'); Io.AsyncMode := True; // So it will create a thread for each input/output task Io.SaveToFile('D:\i1.jpg'); // thread 1 Io.SaveToFile('D:\i2.jpg'); // thread 2 Io.SaveToFile('D:\i3.jpg'); // thread 3 Io.Free; // Free method will wait for all tasks to end! Bmp.Free; End; !!} property AsyncMode: boolean read fAsyncMode write fAsyncMode; procedure WaitThreads(Aborts: Boolean = false); procedure SuspendThreads; {$ifdef IEHASTTHREADSTART} deprecated; {$endif} procedure ResumeThreads; {$ifdef IEHASTTHREADSTART} deprecated; {$endif} {!! TImageEnIO.AcquireParams Declaration property AcquireParams : ; Description AcquireParams is a powerful interface that provides generic access to all image acquistion APIs, Twain, WIA and DCIM Retrieval. AcquireParams accesses , and . If you have called or then you can access common parameters for the device without having to know the API See the TIEAcquireParams object for more details. Demo Demos\ImageAcquisition\AllAcquire\AllAcquire.dpr !!} {$IFDEF IEINCLUDEIEXACQUIRE} property AcquireParams: TIEAcquireParams read fAcquireParams; {$ENDIF} {!! TImageEnIO.TwainParams Declaration property TwainParams: ; Description Use the TwainParams property to control acquisition from Twain scanners and cameras. You can enable/disable the standard user interface, set pixel type (Grayscale, RGB...), DPI, etc. Note: Use TwainParams only when you need access to Twain specific parameters and functionality (when .Api is ieaTwain). For generic access to all image acquisitions sources (Twain, WIA, etc.) use instead. Example // Acquire a black/white (1bit) image from the default Twain device ImageEnView1.IO.TwainParams.PixelType.CurrentValue := 0; if ImageEnView1.IO.SetSource(ieaTwain, Default_Device) then ImageEnView1.IO.Acquire; Demo Demos\ImageAcquisition\Twain\TwainDemo.dpr See Also - - - !!} {$IFDEF IEINCLUDEIEXACQUIRE} property TwainParams: TIETwainParams read fTwainParams; {$ENDIF} {!! TImageEnIO.DCIMParams Declaration property DCIMParams: ; Description Use the DCIMParams property to handle retrieval of images from camera cards and connected camera devices (which appear as USB drives). Notes: - Use DCIMParams only when you need access to DCIM specific functionality (when .Api is ieaDCIM). For generic access to all image acquisitions sources (Twain, WIA, etc.) use instead - Not available in Delphi/C++ Builder 5 !!} {$IFDEF IEINCLUDEWPD} property DCIMParams: TIEDcimAcquire read fDCIMParams; {$ENDIF} {$IFDEF IEINCLUDEIEXACQUIRE} property WIAParams: TIEWia read GetWIAParams; {$ENDIF} // Video capture {$IFDEF IEINCLUDEDIRECTSHOW} property DShowParams: TIEDirectShow read GetDShowParams; {$ENDIF} {$IFDEF IEINCLUDEMEDIAFOUNDATION} property MediaFoundationSourceReader: TIEMediaFoundationSourceReader read GetMediaFoundationSourceReader; {$ENDIF} // PRINTING procedure PrintImageEx(PrintBMP: TIEBitmap; PrtCanvas: TCanvas; dpix, dpiy: integer; pagewidth, pageheight: double; MarginLeft, MarginTop, MarginRight, MarginBottom: double; VerticalPos: TIEVerticalPos; HorizontalPos: TIEHorizontalPos; Size: TIESize; SpecWidth, SpecHeight: double; GammaCorrection: double; bPrinting: Boolean = True); procedure PrintImagePos(PrtCanvas: TCanvas; x, y: double; Width, Height: double; GammaCorrection: double = 1; PrintAnnotations: Boolean = False; PrintLayers: Boolean = False); procedure PrintImagePosEx(PrintBMP: TIEBitmap; PrtCanvas: TCanvas; dpix, dpiy: integer; x, y: double; Width, Height: double; GammaCorrection: double); procedure PrintImage(PrtCanvas: TCanvas = nil; MarginLeft: double = 1; MarginTop: double = 1; MarginRight: double = 1; MarginBottom: double = 1; VerticalPos: TIEVerticalPos = ievpCenter; HorizontalPos: TIEHorizontalPos = iehpCENTER; Size: TIESize = iesFitToPage; SpecWidth: double = 0; SpecHeight: double = 0; GammaCorrection: double = 1; PrintAnnotations: Boolean = False; PrintLayers: Boolean = False); procedure PreviewPrintImage(DestBitmap: TBitmap; MaxBitmapWidth: integer; MaxBitmapHeight: integer; PrinterObj: TPrinter = nil; MarginLeft: double = 1; MarginTop: double = 1; MarginRight: double = 1; MarginBottom: double = 1; VerticalPos: TIEVerticalPos = ievpCenter; HorizontalPos: TIEHorizontalPos = iehpCENTER; Size: TIESize = iesFitToPage; SpecWidth: double = 0; SpecHeight: double = 0; GammaCorrection: double = 1); procedure PreviewPrintImageEx(PrintBMP: TIEBitmap; DestBitmap: TBitmap; MaxBitmapWidth, MaxBitmapHeight: integer; PrinterObj: TPrinter; MarginLeft, MarginTop, MarginRight, MarginBottom: double; VerticalPos: TIEVerticalPos; HorizontalPos: TIEHorizontalPos; Size: TIESize; SpecWidth, SpecHeight: double; GammaCorrection: double); {$IFDEF IEINCLUDEPRINTDIALOGS} function DoPrintPreviewDialog(DialogType: TIEDialogType = iedtDialog; const TaskName: WideString = ''; PrintAnnotations: Boolean = False; const Caption: WideString=''; PrintLayers: Boolean = False): boolean; {!! TImageEnIO.PrintPreviewParams Declaration property PrintPreviewParams: ; Description This property provides access to the parameters of the Print Preview dialog. Note: All measure units are specified by property. !!} property PrintPreviewParams: TIOPrintPreviewParams read fPrintPreviewParams; {$ENDIF} {!! TImageEnIO.PrintingFilterOnSubsampling Declaration property PrintingFilterOnSubsampling: ; Description Specifies a filter when an image needs to be resampled for printing. Filtering enhances the image quality, but slows down processing. !!} property PrintingFilterOnSubsampling: TResampleFilter read fPrintingFilterOnSubsampling write fPrintingFilterOnSubsampling; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-08) // NOTE: Now handled by IEGlobalSettings() property ProxyAddress: WideString read GetProxyAddress write SetProxyAddress; property ProxyUser: WideString read GetProxyUser write SetProxyUser; property ProxyPassword: WideString read GetProxyPassword write SetProxyPassword; {$ENDIF} // property ResetPrinter: boolean read fResetPrinter write fResetPrinter; property PrintLogFile: String read GetPrintLogFile write SetPrintLogFile; published property AttachedImageEn: TIEView read fImageEnView write SetAttachedImageEn; property Background: TColor read GetReBackground write SetReBackground default clBlack; {!! TImageEnIO.OnProgress Declaration property OnProgress: ; Description Occurs during input/output operations. It is commonly used to show task progress. Notes: - If you are using it to update a progress bar then you can reset it in the event. - To access I/O progress for the class of a TImageEnView, use the event. Example procedure TForm1.ImageEnIO1Progress(Sender: TObject; per: Integer); begin // Show load/save progress ProgressBar1.Visible := True; ProgressBar1.Position := per; Application.ProcessMessages; // <- important! end; procedure TForm1.ImageEnIO1FinishWork(Sender: TObject); begin // Hide the progress bar ProgressBar1.Visible := False; end; !!} property OnProgress: TIEProgressEvent read fOnProgress write fOnProgress; property PreviewsParams: TIOPreviewsParams read GetIOPreviewParams write SetIOPreviewParams default []; {!! TImageEnIO.StreamHeaders Declaration property StreamHeaders: boolean; Description If True, each SaveToStreamXXX method adds an additional special header as needed for multi-image streams. When a special header is added, the images saved with SaveToStream*** aren't compatible with LoadFromFile*** methods. Example // Save ImageEnView1 and ImageEnView2 images in the file, images.dat // Note: images.dat won't be loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('bmpimages.dat', fmCreate); ImageEnView1.IO.StreamHeaders := True; ImageEnView1.IO.SaveToStreamJPEG(fs); ImageEnView2.IO.StreamHeaders := True; ImageEnView2.IO.SaveToStreamJPEG(fs); fs.free; End; // Save a single image in image.jpg // image.jpg is loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('image.jpg'); ImageEnView1.IO.StreamHeaders := False; ImageEnView1.IO.SaveToFileJPEG(fs); End; !!} property StreamHeaders: boolean read fStreamHeaders write fStreamHeaders default false; property PreviewFont: TFont read fPreviewFont write SetPreviewFont; property PreviewFontEnabled: Boolean read fPreviewFontEnabled write SetPreviewFontEnabled default false; property AttachedTImage: TImage read fTImage write SetTImage; {!! TImageEnIO.OnIOPreview Declaration property OnIOPreview: ; Description OnIOPreview is called before the preview form is displayed (i.e. when calling the method). Example procedure TForm1.ImageEnIO1IOPreview(Sender: TObject; PreviewForm: TForm); begin with (PreviewForm as TfIOPreviews) do ProgressBar1.Visible := False; end; !!} property OnIOPreview: TIEIOPreviewEvent read fOnIOPreview write fOnIOPreview; {!! TImageEnIO.DialogsMeasureUnit Declaration property DialogsMeasureUnit: Description Specifies the measurement unit used in the Print Preview dialog Example ImageEnView1.IO.DialogsMeasureUnit := ieduCm; ImageEnView1.IO.DoPrintPreviewDialog(iedtDialog); !!} property DialogsMeasureUnit: TIEDialogsMeasureUnit read fDialogsMeasureUnit write fDialogsMeasureUnit default ieduInches; {!! TImageEnIO.AutoAdjustDPI Declaration property AutoAdjustDPI: Boolean; Description When set to True and the current (loaded or scanned) image has a horizontal DPI that does not not equal its vertical DPI, ImageEn will resize the image to make them equal. Default: False !!} property AutoAdjustDPI: boolean read fAutoAdjustDPI write fAutoAdjustDPI default False; {!! TImageEnIO.FilteredAdjustDPI Declaration property FilteredAdjustDPI: Boolean; Description If set to True, ImageEn applies a resampling filter to enhance quality when adjusting an image's DPI. Note: Only valid when is True. It can slow down the loading process. !!} property FilteredAdjustDPI: boolean read fFilteredAdjustDPI write fFilteredAdjustDPI default false; {!! TImageEnIO.OnFinishWork TImageEnMView component Declaration property OnFinishWork: TNotifyEvent; Description OnFinishWork occurs when an input/output task ends. It is useful for resetting a progress bar or to know when a thread ends in a asynchronous mode. Example procedure TForm1.ImageEnIO1Progress(Sender: TObject; per: Integer); begin // Show load/save progress ProgressBar1.Visible := True; ProgressBar1.Position := per; Application.ProcessMessages; // <- important! end; procedure TForm1.ImageEnIO1FinishWork(Sender: TObject); begin // Hide the progress bar ProgressBar1.Visible := False; end; See Also - TImageEnIO.OnProgress - TImageEnView.OnFinishWork !!} property OnFinishWork: TNotifyEvent read fOnFinishWork write fOnFinishWork; {!! TImageEnIO.OnAcquireBitmap Declaration property OnAcquireBitmap: ; Description Occurs whenever a new bitmap is acquired during a multi-page acquisition. Parameter Description Sender Will be either a TImageEnIO or TImageEnMIO control ABitmap A object that contains the acquired image DpiX, DpiY Tne DPI of the acquired image Handled Has no effect when acquiring via a TImageEnView/TImageEnIO
!!} property OnAcquireBitmap: TIEAcquireBitmapEvent read fOnAcquireBitmap write fOnAcquireBitmap; {!! TImageEnIO.OnAcquireClose Declaration property OnAcquireClose: TNotifyEvent; Description Occurs when the user closes the acquire dialog, which was opened using . !!} property OnAcquireClose: TNotifyEvent read fOnAcquireClose write fOnAcquireClose; {!! TImageEnIO.SimplifiedParamsDialogs Declaration property SimplifiedParamsDialogs: Boolean; Description When set to true (the default), the File Format Parameters dialog (shown when clicking the "Advanced" button in ImageEn's Save dialog or using ) will show a simplified set of parameters. Set to false to display a fuller set of parameters. Example The Parameters dialog for TIFF, using SimplifiedParamsDialogs = True: The Parameters dialog for TIFF, using SimplifiedParamsDialogs = False: !!} property SimplifiedParamsDialogs: boolean read fSimplifiedParamsDialogs write fSimplifiedParamsDialogs default true; {!! TImageEnIO.OnDoPreviews Declaration property OnDoPreviews: ; Description OnDoPreviews occurs just before the Format Parameters dialog (shown when clicking the "Advanced" button in ImageEn's Save dialog) shows. You can disable the dialog box by setting Handled to true. !!} property OnDoPreviews: TIEDoPreviewsEvent read fOnDoPreviews write fOnDoPreviews; property NativePixelFormat: boolean read GetNativePixelFormat write SetNativePixelFormat default false; property ImageEnVersion: String read GetImageEnVersion write SetImageEnVersion stored false; end; // TImageEnIO ////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure IEInitialize_imageenio; procedure IEFinalize_imageenio; var iegPrintLogFileName: String; iegPrintLogFile: textfile; function IEFilenameToInternalFileType(const FileName: String; IncludeMultiOnly: Boolean = false): TIOFileType; const // Property strings for TIOPrintPreviewParams.GetProperty/SetProperty PPP_MARGINTOP = 'MARGINTOP'; PPP_MARGINLEFT = 'MARGINLEFT'; PPP_MARGINRIGHT = 'MARGINRIGHT'; PPP_MARGINBOTTOM = 'MARGINBOTTOM'; PPP_POSITION = 'POSITION'; PPP_SIZE = 'SIZE'; PPP_WIDTH = 'WIDTH'; PPP_HEIGHT = 'HEIGHT'; PPP_GAMMA = 'GAMMA'; PPP_PRINTSELECTED = 'PRINTSELECTED'; PPP_PRINTTHUMBNAILS = 'PRINTTHUMBNAILS'; PPP_THUMBNAILCOLUMNS = 'THUMBNAILCOLUMNS'; PPP_THUMBNAILROWS = 'THUMBNAILROWS'; PPP_THUMBNAILSPACING = 'THUMBNAILSPACING'; PPP_THUMBNAILSTYLE = 'THUMBNAILSTYLE'; PPP_THUMBNAILSHOWTEXT = 'THUMBNAILSHOWTEXT'; PPP_DLGWIDTH = 'DLGWIDTH'; PPP_DLGHEIGHT = 'DLGHEIGHT'; PPP_Property_Count = 18; PPP_Property_List : array[0 .. PPP_Property_Count - 1] of string = ( PPP_MARGINTOP , PPP_MARGINLEFT , PPP_MARGINRIGHT , PPP_MARGINBOTTOM , PPP_POSITION , PPP_SIZE , PPP_WIDTH , PPP_HEIGHT , PPP_GAMMA , PPP_PRINTTHUMBNAILS , PPP_THUMBNAILCOLUMNS , PPP_THUMBNAILROWS , PPP_THUMBNAILSPACING , PPP_THUMBNAILSTYLE , PPP_THUMBNAILSHOWTEXT , PPP_DLGWIDTH , PPP_DLGHEIGHT , PPP_PRINTSELECTED); implementation uses {$ifdef IEUSEVCLZLIB}zlib, {$else}iezlib, {$endif} {$IFDEF VIDEO_THUMBNAILS} iexShellThumbnails, {$ENDIF} giffilter, PCXFilter, imscan, tiffilt, jpegfilt, BMPFilt, IOPreviews, pngfilt, pngfiltw, neurquant, ietgafil, IEMIO, IEMView, IEOpenSaveDlg, ieprnform1, ieprnform2, ievect, imageenview, iesettings, iedicom, iej2000, iepsd, iewic, giflzw, tiflzw, ielcms, ieraw, iemiscplugins, ievfw, iexLayers, iexSVG; {$R-} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// type TIEIOMethodTypes = (ieLoadSaveFile, ieLoadSaveFileIF, ieLoadSaveStream, ieLoadSaveFileRetInt, ieLoadSaveFileRetBool, ieLoadSaveFileIFRetBool, ieLoadSaveStreamRetInt, ieLoadSaveStreamRetBool, ieLoadSaveFileFFRetBool, ieLoadSaveStreamFF, ieLoadSaveStreamFTRetBool, ieCaptureFromScreen, ieLoadSaveIndexRetBool, ieImportMetaFileRetBool, ieLoadFromURLRetBool, ieAcquire); TIEIOMethodType_LoadSaveFile = procedure(const FileName: WideString) of object; TIEIOMethodType_LoadSaveFileIF = procedure(const FileName: WideString; FileType: TIOFileType) of object; TIEIOMethodType_LoadSaveStream = procedure(Stream: TStream) of object; TIEIOMethodType_LoadSaveFileRetInt = function(const FileName: WideString): integer of object; TIEIOMethodType_LoadSaveFileRetBool = function(const FileName: WideString): Boolean of object; TIEIOMethodType_LoadSaveFileIFRetBool = function(const FileName: WideString; FileType: TIOFileType): Boolean of object; TIEIOMethodType_LoadSaveStreamRetInt = function(Stream: TStream): integer of object; TIEIOMethodType_LoadSaveStreamRetBool = function(Stream: TStream): Boolean of object; TIEIOMethodType_LoadSaveFileFFRetBool = function(const FileName: WideString; FileFormat: TIOFileType) : Boolean of object; TIEIOMethodType_LoadSaveStreamFF = procedure(Stream: TStream; FileFormat: TIOFileType) of object; TIEIOMethodType_LoadSaveStreamFTRetBool = function(Stream: TStream; FileFormat: TIOFileType) : Boolean of object; TIEIOMethodType_CaptureFromScreen = procedure(Source: TIECSSource; MouseCursor: TCursor) of object; TIEIOMethodType_LoadSaveIndexRetBool = function(Index: integer): Boolean of object; TIEIOMethodType_ImportMetaFileRetBool = function(const FileName: WideString; Width, Height: integer; WithAlpha: boolean): Boolean of object; TIEIOMethodType_LoadFromURLRetBool = function(const URL: WideString) : Boolean of object; TIEIOMethodType_Acquire = function(bResetParams : Boolean = False) : boolean of object; TIEIOThread = class(TThread) private fThreadList: TList; fMethodType: TIEIOMethodTypes; fMethod_LoadSaveFile: TIEIOMethodType_LoadSaveFile; fMethod_LoadSaveFileIF: TIEIOMethodType_LoadSaveFileIF; fMethod_LoadSaveStream: TIEIOMethodType_LoadSaveStream; fMethod_LoadSaveFileRetInt: TIEIOMethodType_LoadSaveFileRetInt; fMethod_LoadSaveFileRetBool : TIEIOMethodType_LoadSaveFileRetBool; fMethod_LoadSaveFileIFRetBool : TIEIOMethodType_LoadSaveFileIFRetBool; fMethod_LoadSaveStreamRetInt: TIEIOMethodType_LoadSaveStreamRetInt; fMethod_LoadSaveStreamRetBool: TIEIOMethodType_LoadSaveStreamRetBool; fMethod_LoadSaveFileFFRetBool: TIEIOMethodType_LoadSaveFileFFRetBool; fMethod_LoadSaveStreamFF: TIEIOMethodType_LoadSaveStreamFF; fMethod_LoadSaveStreamFTRetBool: TIEIOMethodType_LoadSaveStreamFTRetBool; fMethod_CaptureFromScreen: TIEIOMethodType_CaptureFromScreen; fMethod_LoadSaveIndexRetBool: TIEIOMethodType_LoadSaveIndexRetBool; fMethod_ImportMetaFileRetBool: TIEIOMethodType_ImportMetaFileRetBool; fMethod_LoadFromURLRetBool: TIEIOMethodType_LoadFromURLRetBool; fMethod_Acquire: TIEIOMethodType_Acquire; p_nf: WideString; p_ImageFormat: TIOFileType; p_stream: TStream; p_fileformat: TIOFileType; p_source: TIECSSource; p_index: integer; p_width, p_height: integer; p_withalpha: boolean; p_mouseCursor: TCursor; p_URL: WideString; p_ResetParams: Boolean; fThreadID: dword; fOwner: TImageEnIO; procedure Init; public procedure Execute; override; constructor CreateLoadSaveFile(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFile; const in_nf: WideString); constructor CreateLoadSaveFileIF(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileIF; const in_nf: WideString; ImageFormat: TIOFileType); constructor CreateLoadSaveStream(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStream; in_Stream: TStream); constructor CreateLoadSaveFileRetInt(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileRetInt; const in_nf: WideString); constructor CreateLoadSaveFileRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileRetBool; const in_nf: WideString); constructor CreateLoadSaveFileIFRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileIFRetBool; const in_nf: WideString; ImageFormat: TIOFileType); constructor CreateLoadSaveStreamRetInt(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamRetInt; in_Stream: TStream); constructor CreateLoadSaveStreamRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamRetBool; in_Stream: TStream); constructor CreateLoadSaveFileFFRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileFFRetBool; const in_nf: WideString; in_fileformat: TIOFileType); constructor CreateLoadSaveStreamFF(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamFF; in_Stream: TStream; in_fileformat: TIOFileType); constructor CreateLoadSaveStreamFTRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamFTRetBool; in_Stream: TStream; in_fileformat: TIOFileType); constructor CreateCaptureFromScreen(owner: TImageEnIO; InMethod: TIEIOMethodType_CaptureFromScreen; in_source: TIECSSource; in_mouseCursor: TCursor); constructor CreateLoadSaveIndexRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveIndexRetBool; in_index: integer); constructor CreateImportMetaFileRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_ImportMetaFileRetBool; const in_nf: WideString; in_width, in_height: integer; in_withalpha: boolean); constructor CreateAcquire(owner: TImageEnIO; InMethod: TIEIOMethodType_Acquire; bResetParams: Boolean); // dummy is necessary to C++Builder in order to compile constructor CreateLoadFromURLRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadFromURLRetBool; const in_URL: WideString; dummy: Double); property ThreadID: dword read fThreadID; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// {!! TImageEnIO.Create Declaration constructor Create(Owner: TComponent); Description Creates a new instance of TImageEnIO. You can set Owner = nil to create an owner-less component. !!} constructor TImageEnIO.Create(Owner: TComponent); begin inherited Create(Owner); IEGDIPLoadLibrary(); fIEBitmap := TIEBitmap.Create; fIEBitmapCreated := true; // we create fIEBitmap fAsyncThreadsCS := TCriticalSection.Create(); fImageEnViewBitmapChangeHandle := nil; fOnIOPreview := nil; fStreamHeaders := false; fParams := TIOParams.Create( self ); {$IFDEF IEINCLUDEIEXACQUIRE} fAcquireParams := TIEAcquireParams.Create(Self); fTwainParams := TIETwainParams.Create(Self); {$ENDIF} {$IFDEF IEINCLUDEWPD} fDCIMParams := TIEDcimAcquire.Create(Self); {$ENDIF} fBitmap := nil; fImageEnView := nil; fTImage := nil; fBackground := clBlack; fOnIntProgress := DoIntProgress; fOnProgress := nil; fOnFinishWork := nil; fPreviewsParams := []; fPreviewFont := TFont.Create; fPreviewFontEnabled := False; fAborting := false; fDialogsMeasureUnit := ieduInches; fAutoAdjustDPI := False; fFilteredAdjustDPI := false; fAVI_avf := nil; fAVI_avs := nil; fAVI_avs1 := nil; fAVI_gf := nil; {$ifdef IEINCLUDEDIRECTSHOW} fOpenMediaFile := nil; {$endif} fAsyncThreads := TList.Create; fAsyncThreadsFinishEvent := Windows.CreateEvent(nil, false, false, nil); fAsyncMode := false; fPrintingFilterOnSubsampling := rfFastLinear; fgrec := nil; fOnAcquireBitmap := nil; fOnAcquireClose := nil; SimplifiedParamsDialogs := true; fOnDoPreviews := nil; fChangeBackground := false; fDefaultDitherMethod := ieThreshold; fResetPrinter := true; fPS_handle := nil; fPS_stream := nil; fPDF_handle := nil; fPDF_stream := nil; {$IFDEF IEINCLUDEIEXACQUIRE} fWIA := nil; {$ENDIF} {$IFDEF IEINCLUDEDIRECTSHOW} fDShow := nil; {$ENDIF} {$IFDEF IEINCLUDEMEDIAFOUNDATION} fMediaFoundationSourceReader := nil; {$ENDIF} {$IFDEF IEINCLUDEPRINTDIALOGS} fPrintPreviewParams := TIOPrintPreviewParams.Create; {$ENDIF} end; {!! TImageEnIO.CreateFromBitmap Declaration constructor CreateFromBitmap(Bitmap: ); constructor CreateFromBitmap(Bitmap: TBitmap); Description Creates a new instance of TImageEnIO, assigning the property or . Example with TImageEnIO.CreateFromBitmap(myBitmap) do begin DoPrintPreviewDialog( iedtDialog, '' ) Free; end; // If an area of the image is selected, print the selection, otherwise print the whole image procedure TForm1.PrintImageClick(Sender: TObject); var bmp: TIEBitmap; IO: TImageEnIO; begin if ImageEnView1.Selected = False then ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog, '' ) else begin bmp := TIEBitmap.Create; IO := TImageEnIO.CreateFromBitmap( bmp ); try ImageEnView1.CopySelectionToBitmap( bmp ); IO.DoPrintPreviewDialog( iedtDialog, '' ); finally IO.Free; bmp.Free; end; end; end; !!} constructor TImageEnIO.CreateFromBitmap(Bitmap: TIEBitmap); begin Create(nil); AttachedIEBitmap := Bitmap; end; constructor TImageEnIO.CreateFromBitmap(Bitmap: TBitmap); begin Create(nil); AttachedBitmap := Bitmap; end; {!! TImageEnIO.ImageEnVersion Declaration property ImageEnVersion: String; Description Returns the ImageEn version as a string. !!} function TImageEnIO.GetImageEnVersion: String; begin result := IEMAINVERSION; end; procedure TImageEnIO.SetImageEnVersion(Value: String); begin // this is a read-only property, but it must be displayed in object inspector end; procedure TImageEnIO.SetNativePixelFormat(value: Boolean); begin if GetParams <> nil then GetParams.IsNativePixelFormat := value; end; // Sets modified to false for the attached fIEBitmap and imageenview procedure TImageEnIO.ResetModified(AllLayers: Boolean = False); begin if assigned( fIEBitmap ) then fIEBitmap.Modified := False; if assigned( fImageEnView ) and ( fImageEnView is TImageEnView ) then if AllLayers or ( TImageEnView( fImageEnView ).LayersCount = 1 ) then TImageEnView( fImageEnView ).Modified := False; end; {!! TImageEnIO.NativePixelFormat Declaration property NativePixelFormat: Boolean; Description By default, ImageEn converts all paletted images to 24 bit (true color). Only black/white images are stored in the original format with 1 bit per pixel. Setting NativePixelFormat to True disables the conversion and uses the image's native format. Note: must be False to enable NativePixelFormat. Also, use of NativePixelFormat will prevent execution of some image processing operations. Example If you have a 16 bit gray scale TIFF and you want to work with 16 bit gray scale pixels, you must write this before loading the image: ImageEnView1.LegacyBitmap := False; // Do not use Tbitmap ImageEnView1.IO.NativePixelFormat := True; // Use the original pixel format Now you can read the pixels using: word = ImageEnView1.IEBitmap.Pixels_ie16g[x,y]; !!} function TImageEnIO.GetNativePixelFormat: Boolean; begin if GetParams <> nil then result := GetParams.IsNativePixelFormat else result := False; end; {!! TImageEnIO.WaitThreads Declaration procedure WaitThreads(Aborts: Boolean = false); Description Call WaitThreads to wait until all threads complete. If Aborts is True, then all threads will be aborted. Example ImageEnIO.LoadFromFile('C:\input.jpg'); ImageEnIO.AsyncMode := True; // Enable multithreading ImageEnIO.SaveToFile('D:\output1.jpg'); // Save in thread 1 ImageEnIO.SaveToFile('D:\output2.jpg'); // Save in thread 2 ImageEnIO.WaitThreads(false); // Wait until all saving threads terminate !!} procedure TImageEnIO.WaitThreads(Aborts: Boolean); var i: Integer; begin repeat fAsyncThreadsCS.Enter(); if Aborts then fAborting := true; i := fAsyncThreads.Count; fAsyncThreadsCS.Leave(); if i = 0 then break; Windows.WaitForSingleObject(fAsyncThreadsFinishEvent, INFINITE); until false; end; procedure TImageEnIO.SuspendThreads; {$ifdef IEHASTTHREADSTART} deprecated; {$endif} var i: integer; begin fAsyncThreadsCS.Enter(); try for i := 0 to fAsyncThreads.Count - 1 do begin TThread(fAsyncThreads[i]).Suspend; while not TThread(fAsyncThreads[i]).Suspended do sleep(0); // give up the remainder of my current time slice end; finally fAsyncThreadsCS.Leave(); end; end; procedure TImageEnIO.SetAborting(Value: Boolean); begin fAborting := Value; {$IFDEF IEINCLUDEIEXACQUIRE} fAcquireParams.Aborting := Value; {$ENDIF} {$IFDEF IEINCLUDEWPD} fDCIMParams.Aborting := Value; {$ENDIF} end; procedure TImageEnIO.ResumeThreads; {$ifdef IEHASTTHREADSTART} deprecated; {$endif} var i: integer; begin fAsyncThreadsCS.Enter(); try for i := 0 to fAsyncThreads.Count - 1 do if TThread(fAsyncThreads[i]).Suspended then TThread(fAsyncThreads[i]).Resume; finally fAsyncThreadsCS.Leave(); end; end; destructor TImageEnIO.Destroy; begin // wait threads WaitThreads(false); FreeAndNil(fAsyncThreads); Windows.CloseHandle(fAsyncThreadsFinishEvent); // {$ifdef IEINCLUDEDIRECTSHOW} CloseMediaFile; {$endif} CloseAVIFile; // works only if AVI is not closed ClosePSFile; {$ifdef IEINCLUDEPDFWRITING} ClosePDFFile; {$endif} if assigned(fImageEnView) then fImageEnView.RemoveBitmapChangeEvent(fImageEnViewBitmapChangeHandle); FreeAndNil(fParams); {$IFDEF IEINCLUDEIEXACQUIRE} FreeAndNil(fAcquireParams); FreeAndNil(fTwainParams); {$ENDIF} {$IFDEF IEINCLUDEWPD} FreeAndNil(fDCIMParams); {$ENDIF} {$IFDEF IEINCLUDEPRINTDIALOGS} FreeAndNil(fPrintPreviewParams); {$ENDIF} FreeAndNil(fPreviewFont); if fIEBitmapCreated then FreeAndNil(fIEBitmap); {$IFDEF IEINCLUDEIEXACQUIRE} if assigned(fWia) then FreeAndNil(fWia); {$ENDIF} {$IFDEF IEINCLUDEDIRECTSHOW} if assigned(fDShow) then FreeAndNil(fDShow); {$ENDIF} {$IFDEF IEINCLUDEMEDIAFOUNDATION} FreeAndNil(fMediaFoundationSourceReader); {$ENDIF} FreeAndNil(fAsyncThreadsCS); IEGDIPUnLoadLibrary(); inherited; end; procedure TImageEnIO.RecreatedTImageEnViewHandle; begin {$ifdef IEINCLUDEDIRECTSHOW} if assigned(fImageEnView) and assigned(fDShow) and (fDShow.NotifyWindow<>fImageEnView.Handle) then fDShow.SetNotifyWindow(fImageEnView.Handle, IEM_NEWFRAME, IEM_EVENT); {$endif} {$ifdef IEINCLUDEMEDIAFOUNDATION} if assigned(fImageEnView) and assigned(fMediaFoundationSourceReader) then begin fMediaFoundationSourceReader.ClearNotifyReceivers(); fMediaFoundationSourceReader.PushNotifyReceiver( TIEMediaFoundationReaderWindowNotifyReceiver.Create(fImageEnView.Handle, IEM_MEDIAFOUNDATION) ); end; {$endif} end; procedure TImageEnIO.SyncGetHandle; begin if Assigned(fImageEnView) then fImageEnView.Handle; end; {!! TImageEnIO.Update Declaration procedure Update(); Description If TImageEnIO is attached to a (or inherited) object, Update will call the Update method of the relevant control. If TImageEnIO is attached to a TBitmap object, Update sets its Modified property to True. !!} procedure TImageEnIO.Update(); begin // remove alpha if attached to fBitmap if assigned(fBitmap) then fIEBitmap.RemoveAlphaChannel; if assigned(fImageEnView) then begin with fImageEnView do begin if IsInsideAsyncThreads then begin if Parent <> nil then begin {$ifdef IEHASTTHREADSTATICSYNCHRONIZE} if not HandleAllocated then TThread.Synchronize(nil, SyncGetHandle); {$endif} PostMessage(handle, IEM_UPDATE, 0, 0); end; end else Update(); ImageChange; end; end else if assigned(fBitmap) then fBitmap.modified := true; end; // Get actual background color function TImageEnIO.GetReBackground: TColor; begin if assigned(fImageEnView) then result := fImageEnView.Background else result := fBackground; end; {!! TImageEnIO.Background Declaration property Background: TColor; Description The background color of the image (shown in unoccupied areas if the current image is smaller than the control size). Note: When TImageEnIO is attached to , the TImageEnIO.Background is equal to . !!} procedure TImageEnIO.SetReBackground(v: TColor); begin if assigned(fImageEnView) then begin {$IFDEF IEINCLUDEMULTIVIEW} if not (fImageEnView is TImageEnMView) then {$ENDIF} if fChangeBackground then fImageEnView.Background := v; end else fBackground := v; end; function TImageEnIO.IsInsideAsyncThreads: boolean; var i: integer; ch: THandle; begin result := false; ch := GetCurrentThreadId; try fAsyncThreadsCS.Enter(); for i := 0 to fAsyncThreads.Count - 1 do if TIEIOThread(fAsyncThreads.Items[i]).ThreadId = ch then begin result := true; exit; end; finally fAsyncThreadsCS.Leave(); end; end; // Raise exception if there is no bitmap available procedure TImageEnIO.CheckHaveValidBitmap(); var bHaveBitmap: Boolean; begin bHaveBitmap := assigned(fIEBitmap); if assigned( fImageEnView ) and ( fImageEnView is TImageEnView ) and ( TImageEnView( fImageEnView ).fIEBitmapValid = False ) then bHaveBitmap := False; if bHaveBitmap = False then raise EIEException.create( 'Active layer does not contain bitmap' ); end; function TImageEnIO.MakeConsistentBitmap(allowedFormats: TIEPixelFormatSet): boolean; begin CheckHaveValidBitmap(); result := false; if not assigned(fIEBitmap) then exit; if assigned(fBitmap) then fIEBitmap.EncapsulateTBitmap(fBitmap, false); // synchronize fBitmap with fIEBitmap result := fIEBitmap.CheckFormat(allowedFormats, true); end; {!! TImageEnIO.SaveToFileGif Declaration procedure SaveToFileGif(const FileName: WideString); Description Saves the current image to a file in GIF format (89a). The GIF will have a single image and it won't be marked as animated. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Example // Save an interlaced, 64 color Gif. ImageEnView1.IO.Params.GIF_Interlaced := True; ImageEnView1.IO.Params.BitsPerSample := 6; ImageEnView1.IO.Params.SamplesPerPixel := 1; ImageEnView1.IO.SaveToFileGif('D:\image.gif'); !!} procedure TImageEnIO.SaveToFileGIF(const FileName: WideString); var Progress: TProgressRec; fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileGIF, FileName); exit; end; try fAborting := true; fs := nil; try fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; WriteGIFStream(fs, fiebitmap, fParams, Progress); fParams.FileName := FileName; fParams.FileType := ioGIF; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {!! TImageEnIO.InsertToFileGif Declaration function InsertToFileGif(const FileName: WideString): integer; Description Inserts a frame into a GIF file at the position specified by and makes it animated. The file must exist. FileName is the file name including extension. Returns the number of images inside the specified file. Example // Create an animated gif with images contained in ImageEn1 and ImageEn2 components: ImageEnView1.IO.SaveToFileGif('D:\anim.gif'); ImageEnView2.IO.Params.GIF_ImageIndex := 1; ImageEnView2.IO.InsertToFileGif('D:\anim.gif'); !!} function TImageEnIO.InsertToFileGIF(const FileName: WideString): integer; var Progress: TProgressRec; begin // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetInt(self, InsertToFileGIF, FileName); result := -1; exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); result := 0; if not MakeConsistentBitmap([]) then exit; if fParams.GIF_WinWidth < (fiebitmap.width + fParams.GIF_XPos) then fParams.GIF_WinWidth := fiebitmap.width + fParams.GIF_XPos; if fParams.GIF_WinHeight < (fiebitmap.height + fParams.GIF_ypos) then fParams.GIF_WinHeight := fiebitmap.height + fParams.GIF_ypos; result := _InsertGIFIm(FileName, fIEBitmap, fParams, Progress); if not fAborting then _GIFMakeAnimate(string(FileName), 0, fParams.GIF_WinWidth, fParams.GIF_WinHeight); // makes it animated finally DoFinishWork; end; end; {!! TImageEnIO.InsertToFileTIFF Declaration function InsertToFileTIFF(const FileName: WideString): integer; Description Insert a frame into a TIFF file at the position specified by . The file must exist. FileName is the file name including extension. Returns the number of images inside the file. Example // Create a multi-image TIFF from images into two ImageEnViews ImageEnView1.IO.SaveToFile('D:\multi.tif'); // create with a single image ImageEnView2.IO.Params.ImageIndex := 1; // prepare to insert as second image ImageEnView2.IO.InsertToFileTIFF('D:\multi.tif'); !!} function TImageEnIO.InsertToFileTIFF(const FileName: WideString): integer; var Progress: TProgressRec; fs: TIEWideFileStream; begin // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetInt(self, InsertToFileTIFF, FileName); result := -1; exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); result := 0; if not MakeConsistentBitmap([]) then exit; fs := nil; try fs := TIEWideFileStream.Create(FileName, fmOpenReadWrite); fAborting := false; result := TIFFWriteStream(fs, true, fIEBitmap, fParams, Progress); finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {!! TImageEnIO.InsertToStreamTIFF Declaration function InsertToStreamTIFF(Stream: TStream): integer; Description Insert a frame in a TIFF stream at position specified by . The stream position must be at the beginning. Because ImageEn can only write Little-endian TIFF the input file cannot be Big-endian (see ). Returns the number of images inside the file. Example ImageEnView1.IO.Params.ImageIndex := 1; // prepare to insert as second image ImageEnView1.IO.InsertToStreamTIFF(outstream); !!} function TImageEnIO.InsertToStreamTIFF(Stream: TStream): integer; var Progress: TProgressRec; begin // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStreamRetInt(self, InsertToStreamTIFF, Stream); result := -1; exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); result := 0; if not MakeConsistentBitmap([]) then exit; fAborting := false; Stream.Position := 0; result := TIFFWriteStream(Stream, true, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {!! TImageEnIO.ReplaceFileTIFF Declaration function ReplaceFileTIFF(const FileName: WideString): Integer; Description Save the current image into the specified multi-page TIFF file, replacing the image at the index specified by .. Because ImageEn can only write Little-endian TIFF the input file cannot be Big-endian (see ). Examples // We have a multipage tiff, named 'multipage.tif'. // We want to change only the second page (index 1), making it negative. ImageEnView1.IO.Params.TIFF_ImageIndex := 1; // select page ImageEnView1.IO.LoadFromFile('D:\multipage.tif'); ImageEnView1.Proc.Negative; ImageEnView1.IO.ReplaceFileTIFF('D:\multipage.tif'); // Update the file for the selected frame of a multi-page TIFF in a TImageEnMView IO := TImageEnIO.Create(nil); IO.Params.TIFF_ImageIndex := ImageEnMView1.SelectedImage; // select page IO.IEBitmap.Assign( ImageEnMView1.IEBitmap ); IO.ReplaceFileTIFF( ImageEnMView1.MIO.LastFilename ); IO.Free; !!} // replace based on TIFF_ImageIndex function TImageEnIO.ReplaceFileTIFF(const FileName: WideString): integer; begin DeleteTIFFIm(FileName, fParams.TIFF_ImageIndex); result := InsertToFileTIFF(FileName); end; {!! TImageEnIO.ReplaceFileGIF Declaration function ReplaceFileGIF(const FileName: WideString): Integer; Description Save the current image into the specified multi-page GIF file, replacing the image at the index specified by .. Example // We have a multipage GIF, named 'multipage.gif'. // We want to change only the second page (index 1), making it negative. ImageEnView1.IO.Params.GIF_ImageIndex := 1; // select page ImageEnView1.IO.LoadFromFile('D:\multipage.gif'); ImageEnView1.Proc.Negative; ImageEnView1.IO.ReplaceFileTIFF('D:\multipage.gif'); !!} // replace based on GIF_ImageIndex function TImageEnIO.ReplaceFileGIF(const FileName: WideString): integer; begin DeleteGIFIm(FileName, fParams.GIF_ImageIndex); result := InsertToFileGIF(FileName); end; // Performs same function as IEExtToFileFormat but by checking each known extension rather than parsing IEGlobalSettings().FileFormats // IncludeMultiOnly also checks for ioAVI function IEFilenameToInternalFileType(const FileName: String; IncludeMultiOnly: Boolean = false): TIOFileType; var ex: string; begin Result := ioUnknown; ex := string(IEExtractFileExtW(FileName)); if IEFileExtInExtensions( ex, '*.jpg;*.jpeg;*.jpe;*.jif') then result := ioJPEG {$IFDEF IEINCLUDEJPEG2000} else if IEFileExtInExtensions( ex, '*.jp2') then result := ioJP2 else if IEFileExtInExtensions( ex, '*.j2k;*.jpc;*.j2c') then result := ioJ2K {$ENDIF} else if IEFileExtInExtensions( ex, '*.pcx') then result := ioPCX else if IEFileExtInExtensions( ex, '*.dcx') then result := ioDCX else if IEFileExtInExtensions( ex, '*.gif') then result := ioGIF else if IEFileExtInExtensions( ex, '*.tif;*.tiff;*.fax;*.g3f;*.g3n') then result := ioTIFF {$IFDEF IEINCLUDEPNG} else if IEFileExtInExtensions( ex, '*.png') then result := ioPNG {$ENDIF} else if IEFileExtInExtensions( ex, '*.bmp;*.dib;*.rle') then result := ioBMP else if IEFileExtInExtensions( ex, '*.tga;*.targa;*.vda;*.icb;*.vst;*.win') then result := ioTGA else if IEFileExtInExtensions( ex, '*.pxm;*.pbm;*.pgm;*.ppm') then result := ioPXM else if IEFileExtInExtensions( ex, '*.ico') then result := ioICO else if IEFileExtInExtensions( ex, '*.wbmp') then result := ioWBMP else if IEFileExtInExtensions( ex, '*.ps;*.eps') then result := ioPS {$ifdef IEINCLUDEPDFWRITING} else if IEFileExtInExtensions( ex, '*.pdf') and ( IEFileFormatGetInfo( ioPDF ) <> nil ) then result := ioPDF {$endif} {$ifdef IEINCLUDEPSD} else if IEFileExtInExtensions( ex, '*.psd;*.psb') then result := ioPSD {$endif} {$ifdef IEINCLUDEWIC} else if IEFileExtInExtensions( ex, '*.hdp;*.wdp;*.jxr') then result := ioHDP {$endif} {$ifdef IEINCLUDEDICOM} else if IEFileExtInExtensions( ex, '*.dcm;*.dic;*.dicom;*.v2') then result := ioDICOM {$endif} else if IEFileExtInExtensions( ex, '*.all') then result := ioALL else if IEFileExtInExtensions( ex, '*.ien;*.imageen;*.lyr') then result := ioIEN else if IEFileExtInExtensions( ex, '*.cur') then result := ioCUR else if IEFileExtInExtensions( ex, '*.emf') then result := ioEMF else if IEFileExtInExtensions( ex, '*.wmf') then result := ioWMF else if IEFileExtInExtensions( ex, '*.iev') then result := ioIEV else if IEFileExtInExtensions( ex, '*.svg') then result := ioSVG else if IEFileExtInExtensions( ex, Camera_Raw_File_Extensions ) then result := ioRAW else if IncludeMultiOnly and IEFileExtInExtensions( ex, '*.avi') then Result := ioAVI end; {!! TImageEnIO.SaveToFile Declaration procedure SaveToFile(const FileName: WideString; ImageFormat: TIOFileType = -1); Description Saves the current image to Jpeg, Jpeg2000, PNG, TIFF, BMP, WBMP, PS, PDF, PCX, DCX, TGA, PXM, ICO, HDP, GIF, DICOM and any other supported format. FileName is the file name including extension. If FImageFormat is -1, then SaveToFile detects the file format from the extension of the specified filename. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Example ImageEnView1.IO.SaveToFile('D:\rome.jpg'); ImageEnView1.IO.SaveToFile('D:\florence.tif'); ImageEnView1.IO.SaveToFile('D:\venice.gif'); // Saves a 16 color bitmap ImageEnView1.IO.Params.BitsPerSample := 4 ; ImageEnView1.IO.Params.SamplesPerPixel := 1; ImageEnView1.IO.SaveToFile('D:\Italy.bmp'); // Saves a jpeg into output.dat ImageEnView1.IO.SaveToFile('D:\output.dat', ioJPEG); !!} procedure TImageEnIO.SaveToFile(const FileName: WideString; ImageFormat: TIOFileType = -1); var fpi: TIEFileFormatInfo; fs: TIEWideFileStream; Progress: TProgressRec; saveFormat: TIOFileType; begin if FileName = '' then exit; saveFormat := ImageFormat; if saveFormat <= ioUnknown then saveFormat := IEFilenameToInternalFileType( FileName ); if not ( saveFormat in [ ioIEN, ioSVG ]) then CheckHaveValidBitmap(); if saveFormat = ioJPEG then SaveToFileJpeg(FileName) {$IFDEF IEINCLUDEJPEG2000} else if saveFormat = ioJP2 then SaveToFileJP2(FileName) else if saveFormat = ioJ2K then SaveToFileJ2K(FileName) {$ENDIF} else if saveFormat = ioPCX then SaveToFilePCX(FileName) else if saveFormat = ioDCX then SaveToFileDCX(FileName) else if saveFormat = ioGIF then SaveToFileGIF(FileName) else if saveFormat = ioTIFF then SaveToFileTIFF(FileName) {$IFDEF IEINCLUDEPNG} else if saveFormat = ioPNG then SaveToFilePNG(FileName) {$ENDIF} else if saveFormat = ioBMP then SaveToFileBMP(FileName) else if saveFormat = ioTGA then SaveToFileTGA(FileName) else if saveFormat = ioPXM then SaveToFilePXM(FileName) else if saveFormat = ioICO then SaveToFileICO(FileName) else if saveFormat = ioWBMP then SaveToFileWBMP(FileName) else if saveFormat = ioPS then SaveToFilePS(FileName) {$ifdef IEINCLUDEPDFWRITING} else if ( saveFormat = ioPDF ) or ( saveFormat = iomscWPPDF ) then SaveToFilePDF(FileName) {$endif} {$ifdef IEINCLUDEPSD} else if saveFormat = ioPSD then SaveToFilePSD(FileName) {$endif} {$ifdef IEINCLUDEWIC} else if saveFormat = ioHDP then SaveToFileHDP(FileName) {$endif} {$ifdef IEINCLUDEDICOM} else if saveFormat = ioDICOM then SaveToFileDICOM(FileName) {$endif} else if saveFormat = ioIEN then SaveToFileIEN(FileName) else if (saveFormat = ioALL) and (fImageEnView <> nil) then (fImageEnView as TImageEnVect).SaveToFileAll(FileName) else if (saveFormat = ioIEV) and (fImageEnView <> nil) then (fImageEnView as TImageEnVect).SaveToFileIEV(FileName) else if saveFormat = ioSVG then SaveToFileSVG(FileName) else begin // try registered file formats if ImageFormat > -1 then fpi := IEFileFormatGetInfo(ImageFormat) else fpi := IEFileFormatGetInfo2( IEExtractFileExtS( FileName )); if assigned(fpi) and assigned(fpi.WriteFunction) then with fpi do begin // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileIF(self, SaveToFile, FileName, ImageFormat); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; fParams.FileName := FileName; fParams.FileType := FileType; try WriteFunction(fs, fIEBitmap, fParams, Progress); finally FreeAndNil(fs); end; fParams.FileName := FileName; fParams.FileType := fpi.FileType; finally DoFinishWork; end; end else fAborting := True; end; end; {!! TImageEnIO.SaveToStreamGif Declaration procedure SaveToStreamGif(Stream: TStream); Description Saves the current image to a stream in GIF format. If property is true, then a special header is added as required for multi-image streams. Example // Saves images in ImageEnView1 and ImageEnView2 to the file Images.dat // Note: images.dat isn't loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('C:\images.dat', fmCreate); ImageEnView1.IO.StreamHeaders := True; ImageEnView1.IO.SaveToStreamGIF(fs); ImageEnView2.IO.StreamHeaders := True; ImageEnView2.IO.SaveToStreamGIF(fs); fs.free; End; // Saves a single image to image.gif // image.gif is loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('image.gif'); ImageEnView1.IO.StreamHeaders := False; ImageEnView1.IO.SaveToFileGIF(fs); End; !!} procedure TImageEnIO.SaveToStreamGIF(Stream: TStream); var Progress: TProgressRec; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamGIF, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; WriteGIFStream(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {$IFDEF IEINCLUDEIEXACQUIRE} {!! TImageEnIO.Acquire Declaration function Acquire(bResetParams : Boolean = False) : boolean; Description Perform a single image acquisition from the , which may be a camera card, Twain or WIA device. is set when the user chooses a source if you have called or manually set a source using . If bResetParams is True then is called before Acquire to reset the IO parameters (if you have already loaded an image from file). Result is true if there was a successful acquisition. Note: For acquisition of multiple images use TImageEnMIO.Acquire. Demo Demos\ImageAcquisition\AllAcquire\AllAcquire.dpr Examples // Prompt the user to choose a scanner source and then acquire if ImageEnView1.IO.SelectAcquireSource([ieaTwain, ieaWIA, ieaDCIM]) then ImageEnView1.IO.Acquire; // Capture from the default WIA device if ImageEnView1.IO.SetSource(ieaWIA, Default_Device) then ImageEnView1.IO.Acquire; // Select the second Twain device and capture if ImageEnView1.IO.SetSource(ieaTwain, 1) then ImageEnView1.IO.Acquire; // Capture from the Twain device named, CanoScan FB620 if ImageEnView1.IO.SetSource(ieaTwain, 'CanoScan FB620') then ImageEnView1.IO.Acquire; // Retrieve from the camera card listed as H:\ drive if ImageEnView1.IO.SetSource(ieaDCIM, 'H') then ImageEnView1.IO.Acquire; // Capture without a dialog ImageEnView1.IO.AcquireParams.VisibleDialog := False; if ImageEnView1.IO.Acquire then ImageEnView1.IO.SaveToFile('D:\newimage.jpg'); // save scanned image !!} function TImageEnIO.Acquire(bResetParams : Boolean) : boolean; var bHandled: Boolean; begin // calling Acquire after TwainAcquireOpen!!!! if assigned(fgrec) then begin result := true; // there is already a scanner dialog open exit; end; // if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateAcquire(self, Acquire, bResetParams); result := true; exit; end; try fAborting := false; result := false; if not MakeConsistentBitmap([]) then exit; if bResetParams then Params.SetDefaultParams; Result := fAcquireParams.Acquire(fIEBitmap, Params, fOnProgress, NativePixelFormat); if Result then DoAcquireBitmap(fIEBitmap, Params.DpiX, Params.DpiY, bHandled); // Note: bHandled is not used by this Acquire method if Result and (fAcquireParams.SelectedSourceApi = ieaTwain) then begin if fAutoAdjustDPI then AdjustDPI; end; Update(); finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEIEXACQUIRE} {!! TImageEnIO.SelectAcquireSource Declaration function SelectAcquireSource(Apis: = [ieaTwain, ieaWIA]) : boolean; Description Prompts the user with a dialog to select a Twain, WIA or DCIM device. Use Apis to specify which sources are available to the user. Any combination of the following can be used: Value Description ieaTwain Acquire from Twain device ieaWIA Acquire using WIA (scanners or camera) ieaDCIM Read from any connected device containing a DCIM folder (e.g. camera card in a slot or a USB connected camera) using the WPD API
Note: If your location is only [ieTwain] or [ieWIA] then the default Twain/WIA selector is shown. Otherwise a custom device selector is used (Use
to control the language in the custom dialog). Returns False if user press "Cancel" button. Demo Demos\ImageAcquisition\AllAcquire\AllAcquire.dpr Example if ImageEn1.IO.SelectAcquireSource([ieaTwain, ieaWIA]) then begin ImageEn1.IO.Acquire; ImageEn1.IO.SaveToFile('D:\MyImage.jpg'); end; !!} function TImageEnIO.SelectAcquireSource(Apis : TIEAcquireApis = [ieaTwain, ieaWIA]): boolean; // NPC: 16/11/11 begin Result := fAcquireParams.SelectSource(Apis); end; {!! TImageEnIO.SetAcquireSource Declaration function SetAcquireSource(Api : ; Location : Variant) : boolean; Description Programatically set the selected acquisition source by an API type and device. The selected device will be used for subsequent calls to . Result is false if the device cannot be selected (i.e. is not connected or does not exist). The API can be one of the following: Value Description ieaTwain Acquire from Twain device ieaWIA Acquire using WIA (scanners or camera) ieaDCIM Read from any connected device containing a DCIM folder (e.g. camera card in a slot or a USB connected camera) using the WPD API
Location can be one of the following: Value Description Default_Device The default device for that API type will be selected Index An index of a device, e.g. 0 for the first device (ieaTwain/ieaWIA/ieaDCIM) Name The name of a device, e.g. 'CanoScan FB620' (ieaTwain/ieaWIA/ieaDCIM) Path The path of a DCIM folder, e.g. 'I:\DCIM\' (ieaDCIM) Drive Letter The letter of a connected camera card or device containing a DCIM folder, e.g. 'I' (ieaDCIM)
Examples // Acquire from the default Twain device if ImageEnView1.IO.SetAcquireSource(ieaTwain, Default_Device) then ImageEnView1.IO.Acquire; // Select a Twain scanner by name ImageEnView1.IO.SetAcquireSource(ieaTwain, 'CanoScan FB620'); // Select the second WIA device ImageEnView1.IO.SetAcquireSource(ieaWIA, 1); // Acquire from the camera card on H drive if ImageEnView1.IO.SetAcquireSource(ieaDCIM, 'H') then ImageEnView1.IO.Acquire; // Read and restore a source var sDevice : string; ADevice : TIEAcquireSource; begin ... // Read the selected device sDevice := AcquireSourceToStr(ImageEnView1.IO.SelectedAcquireSource); ... end; var sDevice : string; ADevice : TIEAcquireSource; begin ... // Restore the device selection ADevice := StrToAcquireSource(sDevice); ImageEnView1.IO.SetAcquireSource(ADevice.Api, ADevice.Location); ... end; See Also -
- !!} function TImageEnIO.SetAcquireSource(Api: TIEAcquireApi; Location : Variant) : boolean; // NPC: 16/11/11 begin Result := fAcquireParams.SetSource(Api, Location); end; {!! TImageEnIO.SelectedAcquireSource Declaration property SelectedAcquireSource : ; (Read only) Description Returns the acquisition source that is currently active due to selection by the user with or programatically using . A record is returned that provides meta information about the device (SelectedAcquireSource.Name, SelectedAcquireSource.DeviceType) and technical details (SelectedAcquireSource.Api, SelectedAcquireSource.Location). If no device is selected then SelectedAcquireSource.Api will be ieaNone. Examples // Display the selected source if ImageEnView1.IO.SelectedAcquireSource.Api = ieaNone then ShowMessage('No device is selected') else ShowMessage('The selected device is ' + ImageEnView1.IO.SelectedAcquireSource.Name); // Read and restore the selected source var sDevice : string; ADevice : TIEAcquireSource; begin ... // Read the selected device sDevice := AcquireSourceToStr(ImageEnView1.IO.SelectedAcquireSource); ... end; var sDevice : string; ADevice : TIEAcquireSource; begin ... // Restore the device selection ADevice := StrToAcquireSource(sDevice); ImageEnView1.IO.SetAcquireSource(ADevice.Api, ADevice.Location); ... end; See Also - - !!} function TImageEnIO.GetSelectedAcquireSource : TIEAcquireSource; // NPC: 16/11/11 begin Result := fAcquireParams.SelectedSource; end; procedure TImageEnIO.InitializeAcquireSource(bIncludeWIA : Boolean); // NPC: 16/11/11 begin AcquireParams.AttachedTwainParams := fTwainParams; {$IFDEF IEINCLUDEWPD} AcquireParams.AttachedDCIMParams := fDcimParams; {$ENDIF} if bIncludeWIA then AcquireParams.AttachedWIAParams := WIAParams; end; {$ENDIF} function TImageEnIO.SyncLoadFromStreamGIF(Stream: TStream): integer; var p1: int64; bmp, merged, prev: TIEBitmap; numi, reqidx: integer; Progress, Progress2: TProgressRec; im: integer; tempAlphaChannel: TIEMask; dummy2, dummy3: pinteger; act: TIEGIFAction; backx, backy, backw, backh: integer; dx, dy: integer; OriginalPixelFormat: TIEPixelFormat; begin result := 0; bmp := nil; merged := nil; prev := nil; try fAborting := False; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; if fParams.GIF_RAWLoad then begin tempAlphaChannel := nil; ReadGIFStream(Stream, fIEBitmap, numi, fParams, Progress, False, tempAlphaChannel, false); CheckDPI; if assigned(tempAlphaChannel) then begin fIEBitmap.AlphaChannel.CopyFromTIEMask(tempAlphaChannel); FreeAndNil(tempAlphaChannel); end; if assigned(fImageEnView) and (fImageEnView is TImageEnView) then begin with (fImageEnView as TImageEnView).CurrentLayer do begin PosX := fParams.GIF_XPos; PosY := fParams.GIF_YPos; end; end; end else begin p1 := Stream.Position; im := 0; merged := TIEBitmap.Create(); merged.Location := ieMemory; act := ioGIF_None; backw := 0; backh := 0; backx := 0; backy := 0; reqidx := fParams.GIF_ImageIndex; if reqidx > 0 then Progress2 := NullProgressRec( fAborting, False ) else Progress2 := Progress; repeat bmp := TIEBitmap.Create(); Stream.position := p1; fParams.GIF_ImageIndex := im; tempAlphaChannel := nil; ReadGIFStream(Stream, bmp, numi, fParams, Progress2, False, tempAlphaChannel, false); OriginalPixelFormat := bmp.PixelFormat; CheckDPI; dx := imax(fParams.GIF_WinWidth, bmp.Width); dy := imax(fParams.GIF_WinHeight, bmp.Height); if assigned(tempAlphaChannel) then begin bmp.AlphaChannel.CopyFromTIEMask(tempAlphaChannel); FreeAndNil(tempAlphaChannel); end; if numi > 1 then begin if fParams.GIF_Action = ioGIF_RestorePrev then begin // saves current state if not assigned(prev) then prev := TIEBitmap.Create(); prev.Assign(merged); end; if act = ioGIF_RestorePrev then begin // restore previous state if assigned(prev) then merged.Assign(prev); end; if act = ioGIF_DrawBackground then begin merged.FillRect(backx, backy, backx + backw - 1, backy + backh - 1, TRGB2TColor(fParams.GIF_Background)); merged.AlphaChannel.FillRect(backx, backy, backx + backw - 1, backy + backh - 1, 0); end; if (merged.Width = 0) then begin merged.Allocate(dx, dy, ie24RGB); merged.Fill(TRGB2TColor(fParams.GIF_Background)); merged.AlphaChannel.Fill(0); end; if merged.PixelFormat <> ie24RGB then merged.PixelFormat := ie24RGB; if (dx > merged.Width) or (dy > merged.Height) then merged.Resize(dx, dy, TRGB2TColor(fparams.GIF_Background), 255, iehLeft, ievTop); dummy2 := nil; dummy3 := nil; bmp.RenderToTIEBitmap(merged, dummy2, dummy3, nil, fParams.GIF_XPos, fParams.GIF_YPos, bmp.Width, bmp.Height, 0, 0, bmp.Width, bmp.Height, true, false, 255, rfNone, true, ielNormal); bmp.MergeAlphaRectTo(merged, 0, 0, fParams.GIF_XPos, fParams.GIF_YPos, bmp.Width, bmp.Height); merged.AlphaChannel.Full := false; backw := bmp.Width; backh := bmp.Height; backx := fParams.GIF_XPos; backy := fParams.GIF_YPos; FreeAndNil(bmp); bmp := merged; act := fParams.GIF_Action; // act refers to the action of next image fParams.GIF_Action := ioGIF_DrawBackground; fParams.GIF_XPos := 0; fParams.GIF_YPos := 0; end; if fAborting then begin if bmp <> merged then FreeAndNil(bmp); break; end; if numi > 0 then begin Progress.per1 := 100 / numi; fIEBitmap.Assign(bmp); fIEBitmap.PixelFormat := originalPixelFormat; end; if bmp <> merged then FreeAndNil(bmp) else bmp := nil; with Progress do if assigned(fOnProgress) then fOnProgress(Sender, trunc(per1 * im)); if fAborting then break; inc(im); until (im >= numi) or (im - 1 = reqidx); if bmp = merged then bmp := nil; FreeAndNil(merged); fParams.GIF_ImageIndex := reqidx; end; result := numi; if fAutoAdjustDPI then AdjustDPI; if fParams.GIF_FlagTranspColor then Background := TRGB2TCOLOR(fParams.GIF_TranspColor) else Background := TRGB2TCOLOR(fParams.GIF_Background); fParams.FileType := ioGIF; fParams.FileName := ''; Update(); ResetModified(); finally prev.Free(); bmp.Free(); merged.Free(); DoFinishWork; end; end; {!! TImageEnIO.LoadFromFileGIF Declaration function LoadFromFileGIF(const FileName: WideString): integer; Description Loads an image from a GIF file (87a, 89a and animated GIF). FileName is the file name including extension. Returns the number of images contained in GIF file (if this is an animated GIF) or -1 if an error was encountered while loading, such as the file not being GIF format ( will be true). Loading errors due to a file not being available will raise an exception. Note: If =True the result will always be -1 Example // Loads the third frame of an animated gif ImageEnView1.IO.Params.GIF_ImageIndex := 2; ImageEnView1.IO.LoadFromFileGIF('D:\anim.gif'); !!} // return remaining images function TImageEnIO.LoadFromFileGIF(const FileName: WideString): integer; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetInt(self, LoadFromFileGIF, FileName); result := -1; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.create(FileName, fmOpenRead or fmShareDenyWrite); try result := SyncLoadFromStreamGIF(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamGIF Declaration function LoadFromStreamGIF(Stream: TStream): integer; Description Loads an image from a stream containing a GIF file. Returns the number of images contained in the stream (if this is an animated stream) or -1 if an error was encountered while loading, such as the file not being GIF format ( will be true). File access errors will raise an exception. If =True the result will always be -1. Note: If property is True, the stream must have a special header (saved using ). Example // loads a GIF file with LoadfFromStreamGIF var fs: TFileStream; Begin fs := TFileStream.Create('C:\myfile.gif', fmOpenRead); ImageEnView1.IO.LoadFromStreamGIF(fs); fs.free; End; !!} // returns remaining images function TImageEnIO.LoadFromStreamGIF(Stream: TStream): integer; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetInt(self, LoadFromStreamGIF, Stream); result := -1; end else begin result := SyncLoadFromStreamGIF(Stream); if fAborting then Result := -1; end; end; {!! TImageEnIO.LoadFromFileDCX Declaration function LoadFromFileDCX(const FileName: WideString): Boolean; Description Loads an image from a DCX file. FileName is the file name including extension. Result will be false if the file is not a DCX format (and will be true). Loading errors due to a file not being available will raise an exception. Note: You can set the page to load using . property. Example // I want the second page of 'input.dat' (which is a DCX file) ImageEnView1.IO.Params.DCX_ImageIndex := 1; ImageEnView1.IO.LoadFromFileDCX('C:\input.dat'); !!} function TImageEnIO.LoadFromFileDCX(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileDCX, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamDCX(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamDCX Declaration function LoadFromStreamDCX(Stream: TStream): Boolean; Description Loads an image from a stream containing a DCX file. The result will be false if an error is encountered, e.g. the file in the stream is not DCX format ( will be true). Note: You can set the page to load using . property. !!} function TImageEnIO.LoadFromStreamDCX(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamDCX, Stream); Result := True; end else begin Result := SyncLoadFromStreamDCX(Stream); end; end; function TImageEnIO.SyncLoadFromStreamDCX(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; IEDCXReadStream(Stream, fIEBitmap, fParams, Progress, false); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioDCX; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; function TImageEnIO.SyncLoadFromStreamPCX(Stream: TStream; streamhead: boolean): Boolean; var SHead: PCXSHead; lp1: int64; Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; lp1 := 0; if streamhead then begin // load header lp1 := Stream.Position; Stream.Read(SHead, sizeof(PCXSHead)); if IECopy(SHead.id, 1, 3) <> 'PCX' then begin fAborting := true; exit; end; if SHead.id <> 'PCX2' then begin Stream.Position := lp1 + 4; SHead.dim := Stream.Size; end; end else SHead.dim := Stream.Size; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); fIEBitmap.RemoveAlphaChannel; ReadPcxStream(Stream, fIEBitmap, fParams, SHead.dim, Progress, false); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioPCX; Update(); ResetModified(); if streamhead and (SHead.id = 'PCX2') then Stream.Position := lp1 + sizeof(SHead) + SHead.dim; // posiziona alla fine del blocco PCX finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromStreamPCX Declaration function LoadFromStreamPCX(Stream: TStream): Boolean; Description Loads an image from a stream containing a PCX file. The result will be false if an error is encountered, e.g. the file in the stream is not PCX format ( will be true). Note: If property is True, the stream must have a special header (saved using ). Example // loads a PCX file with LoadfFromStreamPCX var fs: TFileStream; Begin fs := TFileStream.Create('myfile.pcx', fmOpenRead); if ImageEnView1.IO.LoadFromStreamPCX(fs) = False then ShowMessage('Not a PCX file!'); fs.free; End; !!} function TImageEnIO.LoadFromStreamPCX(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamPCX, Stream); Result := True; end else begin Result := SyncLoadFromStreamPCX(Stream, fStreamHeaders); end; end; {!! TImageEnIO.LoadFromFilePCX Declaration function LoadFromFilePCX(const FileName: WideString): Boolean; Description Loads an image from a PCX file. Result will be false if the file is not PCX format (and will be false). Loading errors due to a file not being available will raise an exception. FileName is the file name including extension. Example ImageEnView1.IO.LoadFromFilePCX('C:\alfa.pcx'); !!} function TImageEnIO.LoadFromFilePCX(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFilePCX, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamPCX(fs, false); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; function TImageEnIO.SyncLoadFromStreamTIFF(Stream: TStream; streamhead: boolean): integer; var SHead: TIFFSHead; Progress: TProgressRec; p0: int64; tmpAlphaChannel: TIEMask; BufStream: TIEBufferedReadStream; begin BufStream := TIEBufferedReadStream.Create(Stream, 8192, IEGlobalSettings().UseRelativeStreams); fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); try if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; p0 := 0; if streamhead then begin BufStream.read(SHead, sizeof(SHead)); p0 := BufStream.Position; if SHead.id <> 'TIFF' then begin fAborting := true; result := 0; exit; end; end; fIEBitmap.RemoveAlphaChannel; tmpAlphaChannel := nil; TIFFReadStream(fIEBitmap, BufStream, result, fParams, Progress, false, tmpAlphaChannel, not streamhead, false, false, false); CheckDPI; if assigned(tmpAlphaChannel) then begin fIEBitmap.AlphaChannel.CopyFromTIEMask(tmpAlphaChannel); FreeAndNil(tmpAlphaChannel); end; if fAutoAdjustDPI then AdjustDPI; if streamhead then BufStream.Position := p0 + SHead.dim; fParams.FileName := ''; fParams.FileType := ioTIFF; Update(); ResetModified(); finally BufStream.Free; DoFinishWork; end; end; {!! TImageEnIO.LoadFromStreamTIFF Declaration function LoadFromStreamTIFF(Stream: TStream): integer; Description Loads an image from a stream containing a TIFF file (rev. 6.0, Packbits, LZW, CCITT G.3 and G.4). Returns the number of images contained in the stream or -1 if an error was encountered while loading, such as the file not being TIFF format ( will be true). Result will always be -1 if =True. Note: If property is True, the stream must have a special header (saved using ). Example // loads a TIFF file with LoadfFromStreamTIFF var fs: TFileStream; Begin fs := TFileStream.Create('C:\myfile.tif', fmOpenRead); ImageEnView1.IO.LoadFromStreamTIFF(fs); fs.free; End; !!} function TImageEnIO.LoadFromStreamTIFF(Stream: TStream): integer; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetInt(self, LoadFromStreamTIFF, Stream); result := -1; end else begin result := SyncLoadFromStreamTIFF(Stream, fStreamHeaders); if fAborting then Result := -1; end; end; {!! TImageEnIO.LoadFromFileTIFF Declaration function LoadFromFileTIFF(const FileName: WideString): integer: Description Loads an image from a TIFF file (rev. 6.0, Packbits, LZW, CCITT G.3 and G.4). FileName is the file name including extension. Returns the number of images contained in TIFF file. Result will be -1 if an error was encountered while loading, such as the file not being TIFF format ( will be true). Loading errors due to a file not being available will raise an exception. Note: If = True then the result will always be -1. Example // Load the second image in the MyImage.tif file ImageEnView1.IO.Params.TIFF_ImageIndex := 1; ImageEnView1.IO.LoadFromFileTIFF('D:\MyImage.tif'); !!} function TImageEnIO.LoadFromFileTIFF(const FileName: WideString): integer; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetInt(self, LoadFromFileTIFF, FileName); result := -1; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try result := SyncLoadFromStreamTIFF(fs, false); if fAborting then Result := -1; finally FreeAndNil(fs); end; fParams.FileName := FileName; end; function TImageEnIO.LoadVectStream(Stream: TStream; ft: TIOFileType): Boolean; var r: TRect; tempIE: TImageEnVect; begin CheckHaveValidBitmap(); Result := False; case ft of ioIEV: begin if assigned(fImageEnView) and (fImageEnView is TImageEnVect) then with (fImageEnView as TImageEnVect) do begin Result := LoadFromStreamIEV( Stream ); r := ObjectsExtents; Proc.ImageResize(r.Right, r.Bottom); Proc.Fill(CreateRGB(255, 255, 255)); AlphaChannel.Fill(0); end else begin // TImageEnView not associated, renderize image tempIE := TImageEnVect.Create(nil); try tempIE.LegacyBitmap := False; Result := tempIE.LoadFromStreamIEV( Stream ); r := TempIE.ObjectsExtents; tempIE.Proc.ImageResize(r.Right, r.Bottom); tempIE.Proc.Fill(CreateRGB(255, 255, 255)); tempIE.CopyObjectsToBack(); IEBitmap.Assign( tempIE.IEBitmap ); finally tempIE.Free; DoFinishWork; end; end; end; ioALL: begin if assigned(fImageEnView) and (fImageEnView is TImageEnVect) then Result := (fImageEnView as TImageEnVect).LoadFromStreamALL( Stream ) else begin // TImageEnView not associated, renderize image tempIE := TImageEnVect.Create(nil); try tempIE.LegacyBitmap := False; Result := tempIE.LoadFromStreamALL( Stream ); tempIE.LayersMergeAll; tempIE.CopyObjectsToBack(); IEBitmap.Assign( tempIE.IEBitmap ); finally tempIE.Free; DoFinishWork; end; end; end; end; Params.FileType := ft; end; function TImageEnIO.LoadVectFile(const fileName: WideString; ft: TIOFileType): Boolean; var fs: TIEWideFileStream; begin Result := False; if not ft in [ ioIEV, ioALL ] then exit; fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); LoadVectStream( fs, ft ); fParams.FileName := FileName; finally FreeAndNil(fs); end; Params.FileType := ft; end; {!! TImageEnIO.LoadFromFile Declaration function LoadFromFile(const FileName: WideString; bCheckUnknown: Boolean = True): Boolean; overload; function LoadFromFile(const FileName: WideString; FileFormat: ): Boolean; overload; Description Loads an image from the specified file. It recognizes the image format from the filename extension (if ImageFormat is not specified). The source can be also an URL if it has the form 'http://'. FileName is the file name including extension. FileFormat specifies the image format. If specified as ioUnknown, it will use the file's extension. bCheckUnknown if the file extension is not known or is incorrect (e.g. a GIF file named MyImage.jpg), then loading will be attempted by analyzing the file content (in the same way as ) Result will be false if the file is not a recognized file type (and will be false). Loading errors due to a file not being available will raise an exception. Notes: - By default, this routine will fail for files with an invalid extension (e.g. a GIF file named MyImage.jpg) or unknown extension. To avoid this you can use the bCheckUnknown overload or - Can load IEV ( objects) and IEN+IEV formats when is TImageEnView or TImageEnVect. Example // Load the second image in the MyImage.tif file ImageEnView1.IO.Params.TIFF_ImageIndex := 1; ImageEnView1.IO.LoadFromFile('D:\MyImage.tif'); // Load a file even if this file extension is incorrect ImageEnView1.IO.LoadFromFile(sFilename, True); See Also - !!} function TImageEnIO.LoadFromFile(const FileName: WideString; FileFormat: TIOFileType): Boolean; var ext: string; fpi: TIEFileFormatInfo; fs: TIEWideFileStream; Progress: TProgressRec; begin Result := False; if not assigned(fIEBitmap) then exit; if FileName = '' then begin fAborting := True; DoFinishWork; exit; end; if IEGetURLTypeW(FileName) <> ieurlUNKNOWN then begin Result := LoadFromURL(FileName); exit; end; if FileFormat = ioUnknown then FileFormat := FindFileFormat(FileName, ffContentOnly); if FileFormat = ioUnknown then begin fAborting := True; DoFinishWork; exit; end; if FileFormat <> ioIEN then CheckHaveValidBitmap(); if FileFormat = ioAVI then begin OpenAVIFile(FileName); if fAborting then begin DoFinishWork; exit; end; LoadFromAVI(fParams.ImageIndex); CloseAVIFile; Params.Filename := FileName; Params.FileType := ioAVI; Result := True; exit; end; ext := string(IEExtractFileExtW(FileName)); fpi := IEFileFormatGetInfo( FileFormat ); {$ifdef IEINCLUDEDIRECTSHOW} // IEFileFormatGetInfo does not include video files so check if it is one if (fpi = nil) and IEFileExtInExtensions(ext, Supported_MPEG_File_Extensions + Supported_WMV_File_Extensions) then begin OpenMediaFile(FileName); if fAborting then Exit; LoadFromMediaFile(fParams.ImageIndex); CloseMediaFile; Params.Filename := FileName; if Lowercase(ext) = '.wmv' then Params.FileType := ioWMV else Params.FileType := ioMPEG; Result := True; Exit; end; {$endif} if fpi = nil then begin fAborting := True; DoFinishWork; exit; end; if fpi.InternalFormat then case fpi.FileType of ioJPEG : begin Result := LoadFromFileJpeg(FileName); exit; end; {$IFDEF IEINCLUDEJPEG2000} ioJP2 : begin Result := LoadFromFileJP2(FileName); exit; end; ioJ2K : begin Result := LoadFromFileJ2K(FileName); exit; end; {$ENDIF} {$IFDEF IEINCLUDEPNG} ioPNG : begin Result := LoadFromFilePNG(FileName); exit; end; {$ENDIF} {$ifdef IEINCLUDEDICOM} ioDICOM : begin Result := LoadFromFileDICOM(FileName); exit; end; {$endif} ioTIFF : begin LoadFromFileTIFF(FileName); Result := Not fAborting; exit; end; ioPCX : begin Result := LoadFromFilePCX(FileName); exit; end; ioDCX : begin Result := LoadFromFileDCX(FileName); exit; end; ioGIF : begin LoadFromFileGIF(FileName); Result := Not fAborting; exit; end; ioWMF, ioEMF : begin Result := ImportMetaFile(FileName, -1, -1, true); exit; end; ioBMP : begin Result := LoadFromFileBMP(FileName); exit; end; ioCUR : begin Result := LoadFromFileCUR(FileName); exit; end; ioICO : begin Result := LoadFromFileICO(FileName); exit; end; ioTGA : begin Result := LoadFromFileTGA(FileName); exit; end; ioPXM : begin Result := LoadFromFilePXM(FileName); exit; end; ioWBMP : begin Result := LoadFromFileWBMP(FileName); exit; end; {$ifdef IEINCLUDERAWFORMATS} ioRAW : begin Result := LoadFromFileRAW(FileName); exit; end; {$endif} {$ifdef IEINCLUDEPSD} ioPSD : begin Result := LoadFromFilePSD(FileName); exit; end; {$endif} {$ifdef IEINCLUDEWIC} ioHDP : begin Result := LoadFromFileHDP(FileName); exit; end; {$endif} ioIEN : begin Result := LoadFromFileIEN(FileName); exit; end; ioIEV, ioALL: begin Result := LoadVectFile(FileName, fpi.FileType); exit; end; end; // try external formats fAborting := true; // So that fAborting is True if the file is not found fParams.ResetInfo; Params.Filename := ''; Params.FileType := ioUnknown; // try registered file formats if assigned(fpi.ReadFunction) = False then begin DoFinishWork; end else begin // file format supported if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileIFRetBool(self, LoadFromFile, FileName, FileFormat); exit; end; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); fAborting := false; try fParams.FileName := FileName; fParams.FileType := fpi.FileType; fpi.ReadFunction(fs, fIEBitmap, fParams, Progress, False); if fAutoAdjustDPI then AdjustDPI; Update(); ResetModified(); Result := Not fAborting; finally FreeAndNil(fs); DoFinishWork; end; end; end; function TImageEnIO.LoadFromFile(const FileName: WideString; bCheckUnknown: Boolean = True): Boolean; var ff, ff2: TIOFileType; begin Result := False; fAborting := True; // Handle all failures ff2 := ioUnknown; // avoid warning // FIRST LOAD - get type from extension if string(IEExtractFileExtW(FileName)) = '.avi' then ff := ioAVI else ff := IEFilenameToFileFormat( FileName ); if ff <> ioUnknown then Result := LoadFromFile(FileName, ff); // SECOND LOAD - get type from content if ( result = False ) and bCheckUnknown then begin ff2 := FindFileFormat(FileName, ffContentOnly); if ff <> ff2 then Result := LoadFromFile(FileName, ff2); end; // Has DoFinishWork been called? if ( ff = ioUnknown ) and (( bCheckUnknown = False ) or ( ff2 = ioUnknown )) then DoFinishWork; end; {!! TImageEnIO.LoadFromFileAuto Declaration function LoadFromFileAuto(const FileName: WideString): Boolean; dynamic; Description Loads an image from file. Unlike it ignores the file extension, instead it analyzes the file content to determine its format. Result will be false if the file is not a recognized file type (and will be false). Loading errors due to a file not being available will raise an exception. Note: This method can load IEV ( objects) and IEN+IEV formats when is TImageEnView or TImageEnVect. Example ImageEnView1.IO.LoadFromFileAuto('C:\input.dat'); ImageEnView1.IO.LoadFromFileAuto('C:\input.tif'); // a tiff or a RAW? if ImageEnView1.IO.LoadFromFileAuto(sFilename) = False then ShowMessage('Not a supported file type!'); See Also - !!} function TImageEnIO.LoadFromFileAuto(const FileName: WideString): Boolean; var ff: TIOFileType; begin ff := FindFileFormat(FileName, ffFallbackToExtension); Result := LoadFromFile(FileName, ff); end; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-16) function TImageEnIO.LoadFromFileFormat(const FileName: WideString; FileFormat: TIOFileType): Boolean; begin Result := False; fAborting := True; if FileFormat <> ioUnknown then Result := LoadFromFile( FileName, FileFormat ); end; {$endif} {!! TImageEnIO.LoadThumbnailFromExplorer Declaration function LoadThumbnailFromExplorer(const FileName : WideString; iDesiredWidth : Integer = 120; iDesiredHeight : Integer = 120): Boolean; Description Retrieve the thumbnail for the specified file from Windows Explorer. This should work for any format that displays a thumbnail in Windows Explorer, including images and videos. Use iDesiredWidth and iDesiredHeight to specify the size of the thumbnail that you require. The property will be true if the load fails (e.g. if there is not a thumbnail for this file type). Example // Load a thumbnail for a video if ImageEnView1.IO.LoadThumbnailFromExplorer('D:\MyVideo.wmv') = False then ShowMessage('Load Error!'); !!} {$IFDEF VIDEO_THUMBNAILS} function TImageEnIO.LoadThumbnailFromExplorer(const FileName : WideString; iDesiredWidth : Integer = 120; iDesiredHeight : Integer = 120): Boolean; var ABitmap : TBitmap; ex: string; begin Result := False; if not assigned(fIEBitmap) then exit; CheckHaveValidBitmap(); ABitmap := TBitmap.create; try if FileName = '' then begin fAborting := True; exit; end; fAborting := False; if (ExtractExplorerThumbnail(FileName, ABitmap, iDesiredWidth, iDesiredHeight) = False) or (ABitmap.Width < 10) then begin fAborting := True; exit; end; fIEBitmap.CopyFromTBitmap(ABitmap); Params.ResetInfo; Params.Filename := FileName; Params.FileType := FindFileFormat( FileName, ffContentOnly ); if Params.FileType = ioUnknown then begin ex := string(IEExtractFileExtW(FileName)); if IEFileExtInExtensions(ex, Supported_WMV_File_Extensions) then Params.FileType := ioWMV else if IEFileExtInExtensions(ex, Supported_MPEG_File_Extensions) then Params.FileType := ioMPEG; end; Result := Not fAborting; finally ABitmap.Free; DoFinishWork; end; end; {$ENDIF} procedure TImageEnIO.Notification(AComponent: TComponent; Operation: TOperation); begin inherited Notification(AComponent, Operation); if (AComponent = fImageEnView) and (Operation = opRemove) then begin fImageEnView.RemoveBitmapChangeEvent(fImageEnViewBitmapChangeHandle); fImageEnView := nil; end; if (AComponent = fTImage) and (Operation = opRemove) then fTImage := nil; end; procedure TImageEnIO.UpdateAPP138BimResolution; type TPSDResolutionInfo=packed record hRes: longint; // fixed point number: pixels per inch hResUnit: word; // 1=pixels per inch, 2=pixels per centimeter WidthUnit: word; // 1=in, 2=cm, 3=pt, 4=picas, 5=columns vRes: longint; // fixed point number: pixels per inch vResUnit: word; // 1=pixels per inch, 2=pixels per centimeter HeightUnit: word; // 1=in, 2=cm, 3=pt, 4=picas, 5=columns end; PPSDResolutionInfo=^TPSDResolutionInfo; var idx: Integer; data: PAnsiChar; len: Integer; p: Integer; q: Integer; ri: PPSDResolutionInfo; begin idx := fParams.JPEG_MarkerList.IndexOf( JPEG_APP13 ); if idx > - 1 then begin data := fParams.JPEG_MarkerList.MarkerData[idx]; len := fParams.JPEG_MarkerList.MarkerLength[idx]; for p := 0 to len - 1 do begin if CompareMem(@data[p], PAnsiChar('8BIM'#3#237), 6) then // 0x03 0xED (resolution identifier) begin inc(data, p+6); q := IESwapWord(pword(data)^); // name length inc(data, 2); inc(data, q); q := IESwapDWord(pdword(data)^); // structure length inc(data, 4); if q>=sizeof(TPSDResolutionInfo) then begin ri := PPSDResolutionInfo(data); ri^.hRes := IESwapDWord(fParams.DpiX*65536); ri^.vRes := IESwapDWord(fParams.DpiY*65536); ri^.hResUnit := IESwapWord(1); // 1=pixels per inch ri^.vResUnit := IESwapWord(1); // 1=pixels per inch ri^.WidthUnit := IESwapWord(1); // 1=in ri^.HeightUnit := IESwapWord(1); // 1=in end; break; end; end; end; end; {!! TImageEnIO.SaveToStream Declaration procedure SaveToStream(Stream: TStream; FileType: ); Description SaveToStream saves the image to a stream. You must specify the file format (if ioUnknown is specified, the current file type is used). If property is True, an additional special header is added, which is needed for multi-image streams. !!} procedure TImageEnIO.SaveToStream(Stream: TStream; FileType: TIOFileType); var fpi: TIEFileFormatInfo; Progress: TProgressRec; begin if FileType = ioUnknown then FileType := fParams.FileType; if FileType = ioUnknown then FileType := ioJPEG; if not ( FileType in [ ioIEN, ioSVG ]) then CheckHaveValidBitmap(); case FileType of ioTIFF: SaveToStreamTIFF(Stream); ioGIF: SaveToStreamGIF(Stream); ioJPEG: SaveToStreamJPEG(Stream); {$IFDEF IEINCLUDEJPEG2000} ioJP2: SaveToStreamJP2(Stream); ioJ2K: SaveToStreamJ2K(Stream); {$ENDIF} ioPCX: SaveToStreamPCX(Stream); ioDCX: SaveToStreamDCX(Stream); ioBMP: SaveToStreamBMP(Stream); {$IFDEF IEINCLUDEPNG} ioPNG: SaveToStreamPNG(Stream); {$ENDIF} ioTGA: SaveToStreamTGA(Stream); ioPXM: SaveToStreamPXM(Stream); ioICO: SaveToStreamICO(Stream); ioWBMP: SaveToStreamWBMP(Stream); ioPS: SaveToStreamPS(Stream); {$ifdef IEINCLUDEPDFWRITING} iomscWPPDF, ioPDF: SaveToStreamPDF(Stream); {$endif} {$ifdef IEINCLUDEPSD} ioPSD: SaveToStreamPSD(Stream); {$endif} {$ifdef IEINCLUDEWIC} ioHDP: SaveToStreamHDP(Stream); {$endif} {$ifdef IEINCLUDEDICOM} ioDICOM: SaveToStreamDICOM(Stream); {$endif} ioIEN: SaveToStreamIEN(Stream); ioSVG: SaveToStreamSVG(Stream); else begin if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStreamFF(self, SaveToStream, Stream, FileType); exit; end; fpi := IEFileFormatGetInfo(FileType); if assigned(fpi) and assigned(fpi.WriteFunction) then with fpi do begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fParams.FileType := FileType; WriteFunction(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end else fAborting := True; end; end; end; {!! TImageEnIO.LoadFromBuffer Declaration procedure LoadFromBuffer(Buffer: Pointer; BufferSize: Integer; Format: = ioUnknown); Description Loads an image from the specified buffer. Parameter Description Buffer The buffer pointer BufferSize The buffer length in bytes. Format Specifies the expected file format. If Format is ioUnknown, then try to find the format automatically
See also:
Example ImageEnView1.IO.LoadFromBuffer(mybuffer, mybufferlength, ioJPEG); !!} procedure TImageEnIO.LoadFromBuffer(Buffer: Pointer; BufferSize: Integer; Format: TIOFileType); var stream: TIEMemStream; begin if (Buffer = nil) or (BufferSize = 0) then begin fAborting := true; exit; end; stream := TIEMemStream.Create(Buffer, BufferSize); try LoadFromStream( stream, Format ); finally FreeAndNil(stream); end; end; {!! TImageEnIO.SaveToText Declaration procedure SaveToText(Stream: TStream; ImageFormat: ; TextFormat: = ietfASCIIArt); procedure SaveToText(const FileName: WideString; ImageFormat: ; TextFormat: = ietfASCIIArt); Description Saves the current image in the specified text format. Parameters: Parameter Description FileName Output file name. Stream Output stream. ImageFormat Wanted file format. TextFormat Output text format. See allowed values in .
See Also: Example ImageEnView1.IO.LoadFromFile('C:\input.jpg'); ImageEnView1.Proc.Resample(128, -1); ImageEnView1.IO.SaveToText('D:\output.txt', ioUnknown, ietfASCIIArt); !!} procedure TImageEnIO.SaveToText(const FileName: WideString; ImageFormat: TIOFileType; TextFormat: TIETextFormat); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); fs := TIEWideFileStream.Create(FileName, fmCreate); try fParams.FileName := FileName; SaveToText(fs, ImageFormat, TextFormat); finally fs.Free(); end; end; (* ietfPascal: const 'FileName_Extension_Size' = nnnn; 'FileName_Extension' : array [0..'FileName_Extension_Size' - 1] of byte = ( $xx,$xx ); ietfHEX 0xaa,0xbb,etc ietfBase64 /9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAYEBQYF.... *) procedure TImageEnIO.SaveToText(Stream: TStream; ImageFormat: TIOFileType; TextFormat: TIETextFormat); const GR: array [0..9] of AnsiChar = 'W@#*+:., '; var ss, s1: AnsiString; i, j, v: Integer; blen: Integer; ms: TMemoryStream; b: byte; px: PRGB; RedToGrayCoef, GreenToGrayCoef, BlueToGrayCoef: integer; procedure PrepareStream(); begin ss := AnsiString(fParams.FileName); i := IEPos('.', ss); if i > 0 then ss[i] := '_'; s1 := ss + '_Size'; ms := TMemoryStream.Create(); SaveToStream(ms, ImageFormat); ms.Position := 0; blen := ms.Size; end; begin CheckHaveValidBitmap(); ms := nil; try case TextFormat of ietfPascal: begin PrepareStream(); IEStreamWriteLn(Stream, 'const' ); IEStreamWriteLn(Stream, ' ' + s1 + ' = ' + IEIntToStr(blen) + ';'); IEStreamWriteLn(Stream, ' ' + ss + ' : array [0..' + s1 + ' - 1] of byte = (' ); ss := ''; for i := 0 to blen - 2 do begin ms.Read(b, 1); ss := ss + '$' + IEIntToHex(b, 2) + ','; if length(ss) > 70 then begin IEStreamWriteLn(Stream, ' ' + ss); ss := ''; end; end; ms.Read(b, 1); IEStreamWriteLn(Stream, ' ' + ss + '$' + IEIntToHex(b, 2) + ');'); end; ietfHEX: begin PrepareStream(); IEStreamWriteLn(Stream, '\\ Size=' + IEIntToStr(blen)); ss := ''; for i := 0 to blen - 2 do begin ms.Read(b, 1); ss := ss + '0x' + IEIntToHex(b, 2) + ','; if length(ss) > 70 then begin IEStreamWriteLn(Stream, ss); ss := ''; end; end; ms.Read(b, 1); IEStreamWriteLn(Stream, ss + '0x' + IEIntToHex(b, 2)); end; ietfBase64: begin PrepareStream(); IEEncode64(ms, Stream, 76); end; ietfASCIIArt: begin if not MakeConsistentBitmap([ie24RGB]) then exit; RedToGrayCoef := IEGlobalSettings().RedToGrayCoef; GreenToGrayCoef := IEGlobalSettings().GreenToGrayCoef; BlueToGrayCoef := IEGlobalSettings().BlueToGrayCoef; for i := 0 to fIEBitmap.Height - 1 do begin ss := ''; px := fIEBitmap.Scanline[i]; for j := 0 to fIEBitmap.Width - 1 do begin with px^ do v := (r * RedToGrayCoef + g * GreenToGrayCoef + b * BlueToGrayCoef) div 100; v := Trunc((v / 255) * 9); ss := ss + GR[v]; inc(px); end; IEStreamWriteLn(Stream, ss); end; end; end; finally ms.Free(); end; end; {!! TImageEnIO.LoadFromText Declaration procedure LoadFromText(const FileName: WideString; TextFormat: = ietfBase64); procedure LoadFromText(Stream: TStream; TextFormat: = ietfBase64); Description Loads image from text. Parameters: Parameter Description FileName Input file name. Stream Input stream. TextFormat Input text format. Only ietfBase64 is currently supported.
See Also:
Example // save as base64 (inside there is a jpeg) ImageEnView1.IO.LoadFromFile('image.jpg'); ImageEnView1.IO.SaveToText('image.base64', ioJpeg, ietfBase64); // reload back ImageEnView1.IO.LoadFromText('image.base64', ietfBase64); !!} procedure TImageEnIO.LoadFromText(const FileName: WideString; TextFormat: TIETextFormat); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try LoadFromText(fs, TextFormat); finally fs.Free(); end; end; procedure TImageEnIO.LoadFromText(Stream: TStream; TextFormat: TIETextFormat); var ms: TMemoryStream; begin CheckHaveValidBitmap(); case TextFormat of ietfPascal, ietfHex, ietfASCIIArt: raise EIEException.create('Unsupported text format'); ietfBase64: begin ms := TMemoryStream.Create(); try IEDecode64(Stream, ms); ms.Position := 0; LoadFromStream(ms); finally ms.Free(); end; end; end; end; {!! TImageEnIO.LoadFromStream Declaration function LoadFromStream(Stream: TStream; FileFormat: = ioUnknown): Boolean; Description Load an image from the specified stream into the attached or . If FileFormat is ioUnknown the file format is detected by reading the image header (using ). The result will be false if an error is encountered, e.g. the file in the stream is not a recognized format ( will be true). If the property is True, the stream must have a special header (saved with ). Note: This method can load IEV ( objects) and IEN+IEV formats when is TImageEnView or TImageEnVect. Examples // load an image from a stream if ImageEnView1.IO.LoadFromStreamFormat( stm ) = False then ShowMessage('Not an image!'); // load a jpeg from a stream if ImageEnView1.IO.LoadFromStreamFormat( stm, ioJPEG ) = False then ShowMessage('Not a JPEG!'); !!} function TImageEnIO.LoadFromStream(Stream: TStream; FileFormat: TIOFileType = ioUnknown): Boolean; var lp: int64; fpi: TIEFileFormatInfo; Progress: TProgressRec; begin Result := False; if FileFormat = ioUnknown then begin lp := Stream.Position; FileFormat := FindStreamFormat(Stream); Stream.Position := lp; end; if FileFormat <> ioIEN then CheckHaveValidBitmap(); fpi := IEFileFormatGetInfo( FileFormat ); if fpi = nil then begin fAborting := true; exit; end; if fpi.InternalFormat then case FileFormat of ioTIFF : begin LoadFromStreamTIFF(Stream); Result := Not fAborting; end; ioGIF : begin LoadFromStreamGIF(Stream); Result := Not fAborting; end; ioJPEG : Result := LoadFromStreamJPEG(Stream); ioPCX : Result := LoadFromStreamPCX(Stream); ioDCX : Result := LoadFromStreamDCX(Stream); ioBMP : Result := LoadFromStreamBMP(Stream); ioICO : Result := LoadFromStreamICO(Stream); ioCUR : Result := LoadFromStreamCUR(Stream); {$IFDEF IEINCLUDEPNG} ioPNG : Result := LoadFromStreamPNG(Stream); {$ENDIF} {$ifdef IEINCLUDEDICOM} ioDICOM : Result := LoadFromStreamDICOM(Stream); {$endif} ioTGA : Result := LoadFromStreamTGA(Stream); ioPXM : Result := LoadFromStreamPXM(Stream); ioWBMP : Result := LoadFromStreamWBMP(Stream); {$IFDEF IEINCLUDEJPEG2000} ioJP2 : Result := LoadFromStreamJP2(Stream); ioJ2K : Result := LoadFromStreamJ2K(Stream); {$ENDIF} {$ifdef IEINCLUDERAWFORMATS} ioRAW : Result := LoadFromStreamRAW(Stream); {$endif} ioBMPRAW: Result := LoadFromStreamBMPRAW(Stream); {$ifdef IEINCLUDEPSD} ioPSD : Result := LoadFromStreamPSD(Stream); {$endif} {$ifdef IEINCLUDEWIC} ioHDP : Result := LoadFromStreamHDP(Stream); {$endif} ioIEN : Result := LoadFromStreamIEN(Stream); ioIEV, ioALL: begin Result := LoadVectStream(Stream, FileFormat); exit; end; ioWMF, ioEMF: Result := ImportMetafile(Stream); end else begin // unknown or user registered file formats if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStreamFTRetBool(self, LoadFromStream, Stream, FileFormat); Result := True; exit; end; fParams.ResetInfo; Params.Filename := ''; Params.FileType := ioUnknown; if assigned(fpi) and assigned(fpi.ReadFunction) then with fpi do begin // file format supported try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.FileType := FileType; ReadFunction(Stream, fIEBitmap, fParams, Progress, False); if fAutoAdjustDPI then AdjustDPI; Result := Not fAborting; Update(); ResetModified(); finally DoFinishWork; end; end else begin fAborting := True; DoFinishWork; end; end; end; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-16) function TImageEnIO.LoadFromStreamFormat(Stream: TStream; FileFormat: TIOFileType): Boolean; begin Result := LoadFromStream( Stream, FileFormat ); end; {$endif} {!! TImageEnIO.SaveToFilePCX Declaration procedure SaveToFilePCX(const FileName: WideString); Description Saves the current image to a file in PCX format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Example // Saves a 256 color PCX ImageEnView1.IO.Params.BitsPerSample := 8; ImageEnView1.IO.Params.SamplesPerPixel := 1; ImageEnView1.IO.SaveToFilePCX('D:\image.pcx'); !!} procedure TImageEnIO.SaveToFilePCX(const FileName: WideString); var Progress: TProgressRec; fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFilePCX, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try WritePcxStream(fs, fIEBitmap, fParams, Progress); fParams.FileName := FileName; fParams.FileType := ioPCX; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; function TImageEnIO.SyncLoadFromStreamTGA(Stream: TStream): Boolean; var tmpAlphaChannel: TIEMask; Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; tmpAlphaChannel := nil; ReadTGAStream(Stream, fIEBitmap, fParams, Progress, false, tmpAlphaChannel, false); CheckDPI; if assigned(tmpAlphaChannel) then begin fIEBitmap.AlphaChannel.CopyFromTIEMask(tmpAlphaChannel); FreeAndNil(tmpAlphaChannel); end; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioTGA; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromFileTGA Declaration function LoadFromFileTGA(const FileName: WideString): Boolean; Description Loads an image from a TGA file. FileName is the file name including extension. Result will be false if the file is not TGA format (and will be false). Loading errors due to a file not being available will raise an exception. !!} function TImageEnIO.LoadFromFileTGA(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileTGA, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamTGA( fs ); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamTGA Declaration function LoadFromStreamTGA(Stream: TStream): Boolean; Description Loads an image from a stream containing a TGA file. The result will be false if an error is encountered, e.g. the file in the stream is not TGA format ( will be true). !!} function TImageEnIO.LoadFromStreamTGA(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamTGA, Stream); Result := True; end else begin Result := SyncLoadFromStreamTGA( Stream ); end; end; {!! TImageEnIO.SavetoFileTGA Declaration procedure SaveToFileTGA(const FileName: WideString); Description Saves the current image to a file in TGA format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. !!} procedure TImageEnIO.SaveToFileTGA(const FileName: WideString); var Progress: TProgressRec; fs: TIEWideFileStream; iemask: TIEMask; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileTGA, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try if fIEBitmap.HasAlphaChannel then begin iemask := TIEMask.Create; fIEBitmap.AlphaChannel.CopyToTIEMask(iemask); WriteTGAStream(fs, fIEBitmap, fParams, Progress, iemask); FreeAndNil(iemask); end else WriteTGAStream(fs, fIEBitmap, fParams, Progress, nil); fParams.FileName := FileName; fParams.FileType := ioTGA; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamTGA Declaration procedure SaveToStreamTGA(Stream: TStream); Description Saves the current image to a stream in TGA format. Stream is the image stream. !!} procedure TImageEnIO.SaveToStreamTGA(Stream: TStream); var Progress: TProgressRec; iemask: TIEMask; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamTGA, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; if fIEBitmap.HasAlphaChannel then begin iemask := TIEMask.Create; fIEBitmap.AlphaChannel.CopyToTIEMask(iemask); WriteTGAStream(Stream, fIEBitmap, fParams, Progress, iemask); FreeAndNil(iemask); end else WriteTGAStream(Stream, fIEBitmap, fParams, Progress, nil); finally DoFinishWork; end; end; procedure TImageEnIO.SyncSaveToStreamBMP(Stream: TStream); var Progress: TProgressRec; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; BMPWriteStream(Stream, fIEBitmap, fParams, Progress, fParams.BMP_HandleTransparency); finally DoFinishWork; end; end; procedure TImageEnIO.SyncSaveToStreamDCX(Stream: TStream); var Progress: TProgressRec; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; IEDCXInsertStream(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamDCX Declaration procedure SaveToStreamDCX(Stream: TStream); Description Saves the current image to a stream in DCX format. !!} procedure TImageEnIO.SaveToStreamDCX(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamDCX, Stream); end else begin Stream.Size := 0; // this avoid that this function inserts SyncSaveToStreamDCX(Stream); end; end; {!! TImageEnIO.SaveToFileDCX Declaration procedure SaveToFileDCX(const FileName: WideString); Description Saves the current image to a file in DCX format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. !!} procedure TImageEnIO.SaveToFileDCX(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileDCX, FileName); exit; end; fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmCreate); SyncSaveToStreamDCX(fs); fParams.FileName := FileName; fParams.FileType := ioDCX; finally FreeAndNil(fs); end; end; {!! TImageEnIO.InsertToFileDCX Declaration procedure InsertToFileDCX(const FileName: WideString); Description Inserts the current image into the specified DCX file, at the position specified by .. Example ImageEnView1.IO.Params.DCX_ImageIndex := 1; ImageEnView1.IO.InsertToFileDCX('D:\multipage.dcx'); !!} procedure TImageEnIO.InsertToFileDCX(const FileName: WideString); var fs: TIEWideFileStream; begin // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, InsertToFileDCX, FileName); exit; end; fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenReadWrite); SyncSaveToStreamDCX(fs); finally FreeAndNil(fs); end; end; {!! TImageEnIO.SaveToStreamBMP Declaration procedure SaveToStreamBMP(Stream: TStream); Description Saves the current image to a stream in BMP format. If property is True, it adds an additional special header as needed for multi-image streams. Example // Saves ImageEnView1 and ImageEnView2 images in file images.dat // images.dat isn't loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('bmpimages.dat', fmCreate); ImageEnView1.IO.StreamHeaders := True; ImageEnView1.IO.SaveToStreamBMP(fs); ImageEnView2.IO.StreamHeaders := True; ImageEnView2.IO.SaveToStreamBMP(fs); fs.free; End; // Saves a single image in image.bmp // image.bmp is loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('image.bmp'); ImageEnView1.IO.StreamHeaders := False; ImageEnView1.IO.SaveToFileBMP(fs); End; !!} procedure TImageEnIO.SaveToStreamBMP(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamBMP, Stream); end else begin SyncSaveToStreamBMP(Stream); end; end; {!! TImageEnIO.SaveToFileBMP Declaration procedure SaveToFileBMP(const FileName: WideString); Description Saves the current image to a file in BMP format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Example // Saves a 256 color compressed bitmap bitmap ImageEnView1.IO.Params.BitsPerSample := 8; ImageEnView1.IO.Params.SamplesPerPixel := 1; ImageEnView1.IO.Params.BMP_Compression := ioBMP_RLE; ImageEnView1.IO.SaveToFile('D:\Italy.bmp'); !!} procedure TImageEnIO.SaveToFileBMP(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileBMP, FileName); exit; end; fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmCreate); SyncSaveToStreamBMP(fs); fParams.FileName := FileName; fParams.FileType := ioBMP; finally FreeAndNil(fs); end; end; {!! TImageEnIO.SaveToFileTIFF Declaration procedure SaveToFileTIFF(const FileName: WideString); Description Saves the current image to a file in TIFF format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Example ImageEnView1.IO.Params.DocumentName := 'My document'; ImageEnView1.IO.SaveToFileTIFF('C:\image.tiff'); !!} procedure TImageEnIO.SaveToFileTIFF(const FileName: WideString); var Progress: TProgressRec; fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileTIFF, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try TIFFWriteStream(fs, false, fIEBitmap, fParams, Progress); fParams.FileName := FileName; fParams.FileType := ioTIFF; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamTIFF Declaration procedure SaveToStreamTIFF(Stream: TStream); Description Saves the current image to a stream in TIFF format. If property is True, it adds an additional special header as needed for multi-image streams. Example // Saves ImageEnView1 and ImageEnView2 attached images in file images.dat // images.dat isn't loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('bmpimages.dat', fmCreate); ImageEnView1.IO.StreamHeaders := True; ImageEnView1.IO.SaveToStreamTIFF(fs); ImageEnView2.IO.StreamHeaders := True; ImageEnView2.IO.SaveToStreamTIFF(fs); fs.free; End; // Saves a single image in image.tif // image.tif is loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('image.tif'); ImageEnView1.IO.StreamHeaders := False; ImageEnView1.IO.SaveToFileTIFF(fs); End; !!} procedure TImageEnIO.SaveToStreamTIFF(Stream: TStream); var SHead: TIFFSHead; lp1, lp2: int64; Progress: TProgressRec; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamTIFF, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; lp1 := 0; if fStreamHeaders then begin lp1 := Stream.position; Stream.write(SHead, sizeof(SHead)); // create space for TIFF stream header end; TIFFWriteStream(Stream, false, fIEBitmap, fParams, Progress); if fStreamHeaders then begin // salve HEADER-TIFF-STREAM lp2 := Stream.position; Stream.position := lp1; SHead.id := 'TIFF'; SHead.dim := lp2 - lp1 - sizeof(SHead); Stream.Write(SHead, sizeof(SHead)); Stream.position := lp2; end; finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamPCX Declaration procedure SaveToStreamPCX(Stream: TStream); Description Saves the current image to a stream in PCX format. If property is True, it adds an additional special header as needed for multi-image streams. Example // Saves ImageEnView1 and ImageEnView2 attached images in file images.dat // images.dat isn't loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('bmpimages.dat', fmCreate); ImageEnView1.IO.StreamHeaders := True; ImageEnView1.IO.SaveToStreamPCX(fs); ImageEnView2.IO.StreamHeaders := True; ImageEnView2.IO.SaveToStreamPCX(fs); fs.free; End; // Saves a single image in image.pcx // image.pcx is loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('image.pcx'); ImageEnView1.IO.StreamHeaders := False; ImageEnView1.IO.SaveToFilePCX(fs); End; !!} procedure TImageEnIO.SaveToStreamPCX(Stream: TStream); var SHead: PCXSHead; lp1, lp2: int64; Progress: TProgressRec; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamPCX, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; lp1 := 0; if fStreamHeaders then begin lp1 := Stream.position; Stream.write(SHead, sizeof(SHead)); // lascia spazio per header PCX stream end; WritePcxStream(Stream, fIEBitmap, fParams, Progress); if fStreamHeaders and not fAborting then begin // salva HEADER-PCX-STREAM lp2 := Stream.position; Stream.position := lp1; SHead.id := 'PCX2'; SHead.dim := lp2 - lp1 - sizeof(SHead); Stream.Write(SHead, sizeof(SHead)); Stream.position := lp2; end; finally DoFinishWork; end; end; // do parameters previews // return True if user press OK {$IFDEF IEINCLUDEDIALOGIO} {!! TImageEnIO.DoPreviews Declaration function DoPreviews(pp: = [ppAll]): boolean; Description Executes the Previews dialog allowing the user to review and modify the parameters of image file formats (for example, JPEG quality, TIFF compression, etc). pp is the set of image formats parameters to show in the dialog. The style of the dialog is affected by Demo Demos\FullApps\PhotoEn3\ImageEx.dpr Example ImageEnView1.IO.LoadFromFile('C:\myimage.gif'); // loads a GIF image ImageEnView1.IO.DoPreviews([ppGIF]); // sets GIF parameters (background, transparency...) ImageEnView1.IO.SaveToFile('D:\newimage.gif'); // saves some image with new parameters !!} function TImageEnIO.DoPreviews(pp: TPreviewParams = [ppAll]): boolean; var fIOPreviews: TfIOPreviews; Handled: boolean; begin Handled := false; if assigned(fOnDoPreviews) then fOnDoPreviews(self, Handled); if not Handled then begin result := false; if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fIOPreviews := TfIOPreviews.Create(self); fIOPreviews.DefaultLockPreview := ioppDefaultLockPreview in PreviewsParams; fIOPreviews.btnApply.Visible := ioppApplyButton in PreviewsParams; fIOPreviews.Params := GetParams; fIOPreviews.Simplified := fSimplifiedParamsDialogs; fIOPreviews.fDefaultDitherMethod := fDefaultDitherMethod; fIOPreviews.UpdateLanguage(); if fPreviewFontEnabled then fIOPreviews.Font.Assign(fPreviewFont) else fIOPreviews.Font.Assign(IEGetDefaultDialogFont); fIOPreviews.ienSource.SetExternalBitmap( fIEBitmap ); // Use same mouse wheel settings as owner component if assigned( fImageEnView ) and ( fImageEnView is TImageEnView ) then with TImageEnView( fImageEnView ) do begin fIOPreviews.ienSource .MouseWheelParams.Assign( MouseWheelParams ); fIOPreviews.ienPreview.MouseWheelParams.Assign( MouseWheelParams ); end; fIOPreviews.ienSource.Update(); fIOPreviews.ienPreview.Blank; if fIOPreviews.SetPreviewParams(pp) then begin if assigned(fOnIOPreview) then fOnIOPreview(self, fIOPreviews); result := fIOPreviews.ShowModal = mrOk; end; fIOPreviews.ienSource.SetExternalBitmap( nil ); fIOPreviews.Release; Update(); end else result := true; // handled end; {$ENDIF} function TImageEnIO.SyncLoadFromStreamJPEG(Stream: TStream; bCheckHeader: Boolean): Boolean; var sh: TStreamJpegHeader; lp: int64; Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; lp := 0; // avoid warning if bCheckHeader then begin lp := Stream.Position; Stream.Read(sh, sizeof(sh)); // carica header TStreamJpegHeader if sh.ID <> 'JFIF' then // stream header don't exist, reset to beginning Stream.Position := lp; end; fIEBitmap.RemoveAlphaChannel; ReadJpegStream(Stream, nil, fIEBitmap, fParams, Progress, False, false, true, false, true, true, -1, fParams.IsNativePixelFormat); CheckDPI; if bCheckHeader and ( sh.ID = 'JFIF' ) then Stream.Position := lp + sizeof(sh) + sh.dim; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioJPEG; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromFileJpeg Declaration function LoadFromFileJpeg(const FileName: WideString): Boolean; Description Loads an image from a JPEG file. Result will be false if the file is not JPEG format (and will be false). Loading errors due to a file not being available will raise an exception. FileName is the file name including extension. Example ImageEnView1.IO.LoadFromFileJpeg('C:\alfa.jpg'); !!} function TImageEnIO.LoadFromFileJpeg(const FileName: WideString): Boolean; var fs: TIEWideFileStream; XStream: TIEBufferedReadStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileJpeg, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); XStream := TIEBufferedReadStream.Create(fs, 65536); try Result := SyncLoadFromStreamJPEG( XStream, False ); fParams.FileName := FileName; finally FreeAndNil(XStream); FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamJpeg Declaration function LoadFromStreamJpeg(Stream: TStream): Boolean; Description Loads an image from a stream containing a JPEG file. The result will be false if an error is encountered, e.g. the file in the stream is not JPEG format ( will be true). Note: If property is True, the stream must have a special header (saved with ). Example // loads a JPEG file with LoadfFromStreamJPEG var fs: TFileStream; Begin fs := TFileStream.Create('C:\myfile.jpg', fmOpenRead); ImageEnView1.IO.LoadFromStreamJPG(fs); fs.free; End; !!} // at the beginning could be a TStreamJpegHeader structure function TImageEnIO.LoadFromStreamJpeg(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamJpeg, Stream); Result := True; end else begin Result := SyncLoadFromStreamJPEG( Stream, True ); end; end; procedure TImageEnIO.SyncSaveToStreamJpeg(Stream: TStream; streamhead: boolean); var sh: TStreamJpegHeader; lp, lp2: int64; Progress: TProgressRec; buf: pointer; dummy: Boolean; lbuf, mi, i: integer; begin try fAborting := false; Progress.Aborting := @fAborting; if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; lp := 0; if streamhead then begin lp := Stream.position; // save initial position Stream.write(sh, sizeof(sh)); // leaves spaces for the header end; // update APP13 - 8BIM dpi info (Photoshop) resolution. This is overwritten if IPTC is written. UpdateAPP138BimResolution; // update APP13 marker with IPTC_Info if (fParams.IPTC_Info.UserChanged) or ( (fParams.IPTC_Info.Count > 0) and (fParams.JPEG_MarkerList.Count = 0) ) then begin fParams.IPTC_Info.SaveToStandardBuffer(buf, lbuf, true); mi := fParams.JPEG_MarkerList.IndexOf(JPEG_APP13); if buf <> nil then begin // replace or add IPTC marker if mi >= 0 then fParams.JPEG_MarkerList.SetMarker(mi, JPEG_APP13, buf, lbuf) else fParams.JPEG_MarkerList.AddMarker(JPEG_APP13, buf, lbuf); freemem(buf); end else if mi >= 0 then // remove IPTC marker fParams.JPEG_MarkerList.DeleteMarker(mi); end; // Exif info if fParams.EXIF_HasExifData then begin // save in temporary buffer SaveEXIFToStandardBuffer(fParams, buf, lbuf, true); // remove previous EXIF data with fParams.JPEG_MarkerList do for i := 0 to Count - 1 do if (MarkerType[i] = JPEG_APP1) and CheckEXIFFromStandardBuffer(MarkerData[i], MarkerLength[i]) then begin DeleteMarker(i); break; end; // save in APP1 fParams.JPEG_MarkerList.AddMarker(JPEG_APP1, buf, lbuf); freemem(buf); end; // XMP // remove previous XMP data with fParams.JPEG_MarkerList do for i := 0 to Count - 1 do if (MarkerType[i] = JPEG_APP1) and (IEFindXMPFromJpegTag(MarkerData[i], MarkerLength[i]) <> nil) then begin DeleteMarker(i); break; end; if fParams.XMP_Info <> '' then begin // save in temporary buffer IESaveXMPToJpegTag(fParams, buf, lbuf); // save in APP1 fParams.JPEG_MarkerList.AddMarker(JPEG_APP1, buf, lbuf); freemem(buf); end; // ImageEn annotations (TImageEnVect objects) // remove previous ImageEn Annot data with fParams.JPEG_MarkerList do for i := 0 to Count - 1do if (MarkerType[i] = JPEG_APP1) and TIEImageEnAnnot.BufferContainsImageEnAnnot(MarkerData[i], MarkerLength[i], dummy) then begin DeleteMarker(i); break; end; if not fParams.ImageEnAnnot.IsEmpty() then begin // save in temporary buffer fParams.ImageEnAnnot.SaveToBuffer(buf, lbuf); // save in APP1 fParams.JPEG_MarkerList.AddMarker(JPEG_APP1, buf, lbuf); freemem(buf); end; // save jpeg Progress.fOnProgress := fOnIntProgress; Progress.Sender := Self; WriteJpegStream(Stream, fIEBitmap, fParams, Progress); if streamhead then begin lp2 := Stream.position; // saves final position Stream.position := lp; // return to initial position sh.ID := 'JFIF'; sh.dim := lp2 - lp - sizeof(sh); Stream.Write(sh, sizeof(sh)); // Saves header TStreamJpegHeader Stream.position := lp2; // return to final position end; finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamJpeg Declaration procedure SaveToStreamJpeg(Stream: TStream); Description Saves the current image to a stream in JPEG format. If property is True, it adds an additional special header as needed for multi-image streams. Example // Saves ImageEnView1 and ImageEnView2 attached images in file images.dat // images.dat isn't loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('bmpimages.dat', fmCreate); ImageEnView1.IO.StreamHeaders := True; ImageEnView1.IO.SaveToStreamJPEG(fs); ImageEnView2.IO.StreamHeaders := True; ImageEnView2.IO.SaveToStreamJPEG(fs); fs.free; End; // Saves a single image in image.jpg // image.jpg is loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('image.jpg'); ImageEnView1.IO.StreamHeaders := False; ImageEnView1.IO.SaveToFileJPEG(fs); End; !!} procedure TImageEnIO.SaveToStreamJpeg(Stream: TStream); begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamJpeg, Stream); exit; end; SyncSaveToStreamJpeg(Stream, fStreamHeaders); end; {!! TImageEnIO.SaveToFileJpeg Declaration procedure SaveToFileJpeg(const FileName: WideString); Description Saves the current image to a file in JPEG format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Example // Saves a gray levels, progressive jpeg image with quality 70 ImageEnView1.IO.Params.JPEG_ColorSpace := ioJPEG_GRAYLEV; ImageEnView1.IO.Params.JPEG_Quality := 70; ImageEnView1.IO.Params.JPEG_Progressive := True; ImageEnView1.IO.SaveToFileJpeg('C:\image.jpg'); !!} procedure TImageEnIO.SaveToFileJpeg(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileJpeg, FileName); exit; end; fs := TIEWideFileStream.Create(FileName, fmCreate); try SyncSaveToStreamJpeg(fs, false); fParams.FileName := FileName; fParams.FileType := ioJPEG; finally fs.Free(); end; end; {!! TImageEnIO.PreviewFont Declaration property PreviewFont: TFont; Description If is set to True then PreviewFont specifies the font used in the dialog. Note: You should ensure the size of the font matches the length of the dialog controls. Example ImageEnView1.IO.PreviewFont.Name := 'MS Times New Roman'; ImageEnView1.IO.PreviewFontEnabled := True; ImageEnView1.IO.DoPreviews([ppAll]); !!} procedure TImageEnIO.SetPreviewFont(f: TFont); begin fPreviewFont.assign(f); end; {!! TImageEnIO.PreviewFontEnabled Declaration property PreviewFontEnabled: Boolean; Description When set to True then you can use to specify a custom font for the dialogs. Example ImageEnView1.IO.PreviewFont.Name := 'MS Times New Roman'; ImageEnView1.IO.PreviewFontEnabled := True; ImageEnView1.IO.DoPreviews([ppAll]); !!} procedure TImageEnIO.SetPreviewFontEnabled(Value : Boolean); begin fPreviewFontEnabled := Value; end; function TImageEnIO.SyncLoadFromStreamBMP(Stream: TStream): Boolean; var Progress: TProgressRec; tmpAlphaChannel: TIEMask; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; tmpAlphaChannel := nil; BMPReadStream(Stream, fIEBitmap, 0, fParams, Progress, false, false, tmpAlphaChannel, not fParams.BMP_HandleTransparency); CheckDPI; if assigned(tmpAlphaChannel) then begin fIEBitmap.AlphaChannel.CopyFromTIEMask(tmpAlphaChannel); FreeAndNil(tmpAlphaChannel); end; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioBMP; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromStreamBMP Declaration function LoadFromStreamBMP(Stream: TStream): Boolean; Description Loads an image from a stream containing a BMP file. The result will be false if an error is encountered, e.g. the file in the stream is not BMP format ( will be true). Note: If property is True, the stream must have a special header (saved with ). Example // loads a BMP file with LoadfFromStreamBMP var fs: TFileStream; Begin fs := TFileStream.Create('C:\myfile.bmp', fmOpenRead); ImageEnView1.IO.LoadFromStreamBMP(fs); fs.free; End; !!} function TImageEnIO.LoadFromStreamBMP(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamBMP, Stream); Result := True; end else begin Result := SyncLoadFromStreamBMP(Stream); end; end; {!! TImageEnIO.LoadFromFileBMP Declaration function LoadFromFileBMP(const FileName: WideString): Boolean; Description Loads an image from a BMP file. FileName is the file name including extension. Result will be false if the file is not BMP format (and will be false). Loading errors due to a file not being available will raise an exception. Example ImageEnView1.IO.LoadFromFileBMP('C:\myimage.bmp'); !!} function TImageEnIO.LoadFromFileBMP(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileBMP, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamBMP(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.AssignParams Declaration procedure AssignParams(Source: TObject); Description Assign the file format parameters from another TImageEnIO component or object. !!} // Copy only Params procedure TImageEnIO.AssignParams(Source: TObject); begin if Source is TImageEnIO then fParams.assign((Source as TImageEnIO).Params) else if Source is TIOParams then fParams.assign(Source as TIOParams); end; // reset fBitmap (called from RegisterBitmapChangeEvent) procedure TImageEnIO.OnBitmapChange(Sender: TObject; destroying: boolean); begin if destroying then begin fImageEnView := nil; end else if assigned(fImageEnView) then begin if assigned(fIEBitmap) then begin fIEBitmap := fImageEnView.IEBitmap; fBitmap := nil; // both fBitmap and fIEBitmap aren't allowed if not encapsulated end else if assigned(fBitmap) then begin fBitmap := fImageEnView.Bitmap; if fIEBitmapCreated then fIEBitmap.EncapsulateTBitmap(fBitmap, true) end; end; end; {$IFDEF IEINCLUDEPNG} function TImageEnIO.SyncLoadFromStreamPNG(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fParams.PNG_Background := tcolor2trgb(Background); fIEBitmap.RemoveAlphaChannel; ReadPNGStream(Stream, fIEBitmap, fParams, Progress, false); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioPNG; Background := TRGB2TCOLOR(fParams.PNG_Background); Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromFilePNG Declaration function LoadFromFilePNG(const FileName: WideString): Boolean; Description Loads an image from a PNG file. FileName is the file name including extension. Result will be false if the file is not PNG format (and will be false). Loading errors due to a file not being available will raise an exception. !!} function TImageEnIO.LoadFromFilePNG(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFilePNG, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamPNG(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {$ENDIF} {$IFDEF IEINCLUDEPNG} {!! TImageEnIO.LoadFromStreamPNG Declaration function LoadFromStreamPNG(Stream: TStream): Boolean; Description Loads an image from a stream containing a PNG file. The result will be false if an error is encountered, e.g. the file in the stream is not PNG format ( will be true). !!} function TImageEnIO.LoadFromStreamPNG(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamPNG, Stream); Result := True; end else begin Result := SyncLoadFromStreamPNG(Stream); end; end; {$ENDIF} {$IFDEF IEINCLUDEPNG} {!! TImageEnIO.SaveToFilePNG Declaration procedure SaveToFilePNG(const FileName: WideString); Description Saves the current image to a file in PNG format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Example // Set best compression ImageEnView1.IO.Params.PNG_Filter := ioPNG_FILTER_PAETH; ImageEnView1.IO.Params.PNG_Compression := 9; // Save PNG ImageEnView1.IO.SaveToFilePNG('D:\max.png'); !!} procedure TImageEnIO.SaveToFilePNG(const FileName: WideString); var fs: TIEWideFileStream; Progress: TProgressRec; iemask: TIEMask; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFilePNG, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try if fIEBitmap.HasAlphaChannel then begin iemask := TIEMask.Create(); fIEBitmap.AlphaChannel.CopyToTIEMask(iemask); WritePNGStream(fs, fIEBitmap, fParams, Progress, iemask); FreeAndNil(iemask); end else WritePNGStream(fs, fIEBitmap, fParams, Progress, nil); fParams.FileName := FileName; fParams.FileType := ioPNG; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEPNG} {!! TImageEnIO.SaveToStreamPNG Declaration procedure SaveToStreamPNG(Stream: TStream); Description Saves the current image to a stream in PNG format. Example // Set best compression ImageEnView1.IO.Params.PNG_Filter := ioPNG_FILTER_PAETH; ImageEnView1.IO.Params.PNG_Compression := 9; // Save PNG ImageEnView1.IO.SaveToStreamPNG(Stream); !!} procedure TImageEnIO.SaveToStreamPNG(Stream: TStream); var Progress: TProgressRec; iemask: TIEMask; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamPNG, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if fIEBitmap.HasAlphaChannel then begin iemask := TIEMask.Create; fIEBitmap.AlphaChannel.CopyToTIEMask(iemask); WritePNGStream(Stream, fIEBitmap, fParams, Progress, iemask); FreeAndNil(iemask); end else WritePNGStream(Stream, fIEBitmap, fParams, Progress, nil); finally DoFinishWork; end; end; {$ENDIF} {$ifdef IEINCLUDEDICOM} function TImageEnIO.SyncLoadFromStreamDICOM(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; IEDicomRead(Stream, fParams, fIEBitmap, Progress, false); fParams.FileName := ''; fParams.FileType := ioDICOM; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromFileDICOM Declaration function LoadFromFileDICOM(const FileName: WideString): Boolean; Description Loads an image from a DICOM file. This method is necessary for DICOM files that don't have an extension or a valid DICOM header, but you know to be DICOM format. FileName is the file name including extension. Result will be false if the file is not DICOM format (and will be false). Loading errors due to a file not being available will raise an exception. Note: DICOM parameters are stored in Demo Demos\InputOutput\Dicom\Dicom.dpr Example ImageEnView1.IO.LoadFromFileDICOM('heart.dcm'); Load the second image of a multiple image DICOM ImageEnView1.IO.Params.ImageIndex := 1; ImageEnView1.IO.LoadFromFileDICOM('D:\MyImage.dcm'); !!} function TImageEnIO.LoadFromFileDICOM(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileDICOM, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamDICOM(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamDICOM Declaration function LoadFromStreamDICOM(Stream: TStream): Boolean; Description Loads an image from a stream containing a DICOM file. The result will be false if an error is encountered, e.g. the file in the stream is not DICOM format ( will be true). Note: DICOM parameters are stored in . !!} function TImageEnIO.LoadFromStreamDICOM(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamDICOM, Stream); Result := True; end else begin Result := SyncLoadFromStreamDICOM(Stream); end; end; procedure TImageEnIO.SyncSaveToStreamDICOM(Stream: TStream); var Progress: TProgressRec; context: pointer; iBitsPerSample, iSamplesPerPixel: Integer; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if not ( fIEBitmap.PixelFormat in [ ie1g, ie8g, ie16g, ie24RGB ] ) then raise EIEException.Create('DICOM saving: unsupported pixel format'); IEPixelFormatToBPSAndSPP( fIEBitmap.PixelFormat, iBitsPerSample, iSamplesPerPixel ); fParams.BitsPerSample := iBitsPerSample; fParams.SamplesPerPixel := iSamplesPerPixel; fParams.Width := fIEBitmap.Width; fParams.Height := fIEBitmap.Height; context := IEDicomWrite_init(Stream, fParams, 1, Progress); IEDicomWrite_addImage(context, fIEBitmap); IEDicomWrite_finalize(context); finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamDicom Declaration procedure SaveToStreamDicom(Stream: TStream); Description Saves the current image to a stream in DICOM format. If property is true, then a special header is added as required for multi-image streams. Example // Saves images in ImageEnView1 and ImageEnView2 to the file Images.dat // Note: images.dat isn't loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('C:\images.dat', fmCreate); ImageEnView1.IO.StreamHeaders := True; ImageEnView1.IO.SaveToStreamDicom(fs); ImageEnView2.IO.StreamHeaders := True; ImageEnView2.IO.SaveToStreamDicom(fs); fs.free; End; // Saves a single image to image.Dicom // image.Dicom is loadable with LoadFromFileXXX methods var fs: TFileStream; Begin fs := TFileStream.Create('image.Dicom'); ImageEnView1.IO.StreamHeaders := False; ImageEnView1.IO.SaveToFileDicom(fs); End; !!} procedure TImageEnIO.SaveToStreamDICOM(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamDICOM, Stream); end else begin SyncSaveToStreamDICOM(Stream); end; end; {!! TImageEnIO.SaveToFileDicom Declaration procedure SaveToFileDicom(const FileName: WideString); Description Saves the current image to a file in Dicom medical imaging format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Demo Demos\InputOutput\Dicom\Dicom.dpr Example ImageEnView1.IO.SaveToFileDicom('D:\image.dicom'); !!} procedure TImageEnIO.SaveToFileDICOM(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileDICOM, FileName); exit; end; fs := TIEWideFileStream.Create(FileName, fmCreate); try SyncSaveToStreamDICOM(fs); fParams.FileName := FileName; fParams.FileType := ioDICOM; finally FreeAndNil(fs); end; end; {$endif} // IEINCLUDEDICOM {!! TImageEnIO.PreviewsParams Declaration property PreviewsParams: ; Description Specifies the features of the File Format Parameters dialog. Example ImageEnView1.IO.PreviewsParams := [ioppDefaultLockPreview]; ImageEnView1.IO.DoPreviews([ppTIFF]); !!} procedure TImageEnIO.SetIOPreviewParams(v: TIOPreviewsParams); begin fPreviewsParams := v; end; function TImageEnIO.GetIOPreviewParams: TIOPreviewsParams; begin result := fPreviewsParams; end; function TImageEnIO.SyncLoadFromStreamICO(Stream: TStream): Boolean; var Progress: TProgressRec; tmpAlphaChannel: TIEMask; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} tmpAlphaChannel := nil; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; ICOReadStream(Stream, fIEBitmap, fParams, false, Progress, tmpAlphaChannel, false); CheckDPI; if assigned(tmpAlphaChannel) then fIEBitmap.AlphaChannel.CopyFromTIEMask(tmpAlphaChannel); if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioICO; Update(); ResetModified(); finally tmpAlphaChannel.Free; DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromFileICO Declaration function LoadFromFileICO(const FileName: WideString): Boolean; Description Loads an image from an icon file. FileName is the file name including extension. Result will be false if the file is not ICO format (and will be false). Loading errors due to a file not being available will raise an exception. Demo Demos\FullApps\PlainIconEditor\PlainIconEditor.dpr Example ImageEnView1.IO.LoadFromFileICO('C:\gates.ico'); !!} function TImageEnIO.LoadFromFileICO(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileICO, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamICO(fs); finally FreeAndNil(fs); end; fParams.FileName := FileName; end; {!! TImageEnIO.LoadFromStreamICO Declaration function LoadFromStreamICO(Stream: TStream): Boolean; Description Loads an image from a stream containing an icon file. The result will be false if an error is encountered, e.g. the file in the stream is not ICO format ( will be true). !!} function TImageEnIO.LoadFromStreamICO(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamICO, Stream); Result := True; end else begin Result := SyncLoadFromStreamICO(Stream); end; end; function TImageEnIO.SyncLoadFromStreamCUR(Stream: TStream): Boolean; var Progress: TProgressRec; tmpAlphaChannel: TIEMask; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} tmpAlphaChannel := nil; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; CURReadStream(Stream, fIEBitmap, fParams, false, Progress, tmpAlphaChannel, false); CheckDPI; if assigned(tmpAlphaChannel) then fIEBitmap.AlphaChannel.CopyFromTIEMask(tmpAlphaChannel); if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioCUR; Update(); ResetModified(); finally tmpAlphaChannel.Free; DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromStreamCUR Declaration function LoadFromStreamCUR(Stream: TStream): Boolean; Description Loads an image from a stream containing a cursor file. The result will be false if an error is encountered, e.g. the file in the stream is not CUR format ( will be true). !!} function TImageEnIO.LoadFromStreamCUR(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamCUR, Stream); Result := True; end else begin Result := SyncLoadFromStreamCUR(Stream); end; end; {!! TImageEnIO.LoadFromFileCUR Declaration function LoadFromFileCUR(const FileName: WideString): Boolean; Description Loads an image from a cursor file. FileName is the file name including extension. Result will be false if the file is not ICO format (and will be false). Loading errors due to a file not being available will raise an exception. Example ImageEnView1.IO.LoadFromFileCUR('C:\gates.cur'); !!} function TImageEnIO.LoadFromFileCUR(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileCUR, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamCUR(fs); finally FreeAndNil(fs); end; fParams.FileName := FileName; end; procedure IEMetafileCalcDestSize(metaWidth, metaheight: integer; requiredWidth, requiredHeight: integer; out dstWidth: integer; out dstHeight: integer); begin dstWidth := metaWidth; dstHeight := metaHeight; if (requiredWidth > 0) or (requiredHeight > 0) then begin if (requiredWidth > 0) and (requiredHeight > 0) then begin dstWidth := requiredWidth; dstHeight := requiredHeight; end else begin if requiredWidth < 0 then begin dstWidth := (metaWidth * requiredHeight) div metaHeight; dstHeight := requiredHeight; end else if requiredHeight < 0 then begin dstHeight := (metaHeight * requiredWidth) div metaWidth; dstWidth := requiredWidth; end; end; end; if (dstWidth > IEGlobalSettings().MaxImageEMFSize) or (dstHeight > IEGlobalSettings().MaxImageEMFSize) then begin if dstHeight > dstWidth then begin dstWidth := (dstWidth * IEGlobalSettings().MaxImageEMFSize) div dstHeight; dstHeight := IEGlobalSettings().MaxImageEMFSize; end else begin dstHeight := (dstHeight * IEGlobalSettings().MaxImageEMFSize) div dstWidth; dstWidth := IEGlobalSettings().MaxImageEMFSize; end; end; end; {!! TImageEnIO.ImportMetafile Declaration function ImportMetafile(const FileName: WideString; Width, Height: Integer; WithAlpha: Boolean): Boolean; function ImportMetafile(Stream: TStream; Width: Integer = -1; Height: Integer = -1; WithAlpha: boolean = True): Boolean; function ImportMetafile(meta: TMetafile; Width: Integer = -1; Height: Integer = -1; WithAlpha: Boolean = True): Boolean; function ImportMetafile(meta: TIEMetafile; Width: Integer = -1; Height: Integer = -1; WithAlpha: Boolean = True); Boolean; Description Imports a WMF or EMF vectorial image. If the file does not represent a valid image format, ImportMetafile raises an EInvalidGraphic exception. Width and Height specify the image size (the rectangle where the vectorial image will be painted). To maintain the image aspect ratio set only one size, assigning -1 to the other, e.g. ImportMetafile('axi.emf', -1, 500); If WithAlpha is true then ImportMetaFile creates an alpha channel, making only the metafile content visible. Note: ImportMetafile converts the vectorial image to a raster image, so you must limit the rasterized image sizes. The maximum allowed size is stored in the public field named . Example // import vectorial image 'alfa.wmf', resizing to 500xHHH (HHH is autocalculated) ImageEnView1.IO.ImportMetafile('C:\alfa.wmf', 500, -1, true); !!} // If Width or Height is -1 then it is auto-calculated maintain aspect ratio // Import... because this is a vectorial image // SHOULD NOT BE IN THREADS BECAUSE USE TCANVAS AND TMETAFILE!! function TImageEnIO.ImportMetaFile(meta: TMetaFile; Width, Height: Integer; WithAlpha: Boolean): Boolean; var dib: TIEDibBitmap; dibcanvas: TCanvas; x, y: integer; px: pbyte; p_rgb: PRGB; w, h: integer; dstWidth, dstHeight: integer; begin Result := False; fAborting := false; if (meta.Width = 0) or (meta.Height = 0) then begin fAborting := true; exit; end; if (Width = 0) or (Height = 0) then exit; if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo(); IEMetafileCalcDestSize(meta.Width, meta.Height, Width, Height, dstWidth, dstHeight); meta.Width := dstWidth; meta.Height := dstHeight; dib := TIEDibBitmap.Create; dibcanvas := TCanvas.Create; try dib.AllocateBits(meta.Width, meta.Height, 24); dibcanvas.Handle := dib.HDC; fParams.FileName := ''; if meta.Enhanced then fParams.FileType := ioEMF else fParams.FileType := ioWMF; fParams.BitsPerSample := 8; fParams.SamplesPerPixel := 3; fParams.Width := dib.Width; fParams.Height := dib.Height; fParams.ImageCount := 1; fParams.OriginalWidth := dib.Width; fParams.OriginalHeight := dib.Height; fParams.DpiX := IEGlobalSettings().DefaultDPIX; fParams.DpiY := IEGlobalSettings().DefaultDPIY; fParams.FreeColorMap; dibCanvas.Brush.Color := GetReBackground; dibcanvas.Brush.Style := bsSolid; dibCanvas.FillRect(rect(0, 0, dib.Width, dib.Height)); dibCanvas.Draw(0, 0, meta); fIEBitmap.CopyFromTDibBitmap(dib); finally FreeAndNil(dibcanvas); FreeAndNil(dib); end; // alpha channel fIEBitmap.RemoveAlphaChannel(); if WithAlpha then begin dib := TIEDibBitmap.Create; dibcanvas := TCanvas.Create; try dib.AllocateBits(meta.Width, meta.Height, 24); dibcanvas.Handle := dib.HDC; dibCanvas.Brush.Color := $00010203; // transparent color (we hope it isn't in the image) dibcanvas.Brush.Style := bsSolid; dibCanvas.FillRect(rect(0, 0, dib.Width, dib.Height)); dibcanvas.Draw(0, 0, meta); w := fIEBitmap.AlphaChannel.Width; h := fIEBitmap.AlphaChannel.Height; for y := 0 to h - 1 do begin px := fIEBitmap.AlphaChannel.Scanline[y]; p_rgb := dib.Scanline[y]; for x := 0 to w - 1 do begin with p_rgb^ do if (b = $01) and (g = $02) and (r = $03) then px^ := 0 else px^ := 255; inc(p_rgb); inc(px); end; end; fIEBitmap.AlphaChannel.SyncFull; finally FreeAndNil(dibcanvas); FreeAndNil(dib); end; end; Result := Not fAborting; Update(); ResetModified(); end; function TImageEnIO.ImportMetafile(meta: TIEMetafile; Width: Integer; Height: Integer; WithAlpha: Boolean): Boolean; var i, j: integer; px: PRGBA; dstWidth, dstHeight: integer; bmp: TIEBitmap; bg: TRGB; begin Result := False; fAborting := false; if (meta.Width = 0) or (meta.Height = 0) then begin fAborting := true; exit; end; if (Width = 0) or (Height = 0) then exit; if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo(); IEMetafileCalcDestSize(meta.Width, meta.Height, Width, Height, dstWidth, dstHeight); bmp := TIEBitmap.Create(dstWidth, dstHeight, ie32RGB); try fParams.FileName := ''; if meta.IsWmf() then fParams.FileType := ioWMF else fParams.FileType := ioEMF; fParams.BitsPerSample := 8; fParams.SamplesPerPixel := 3; fParams.Width := dstWidth; fParams.Height := dstHeight; fParams.ImageCount := 1; fParams.OriginalWidth := dstWidth; fParams.OriginalHeight := dstHeight; fParams.DpiX := IEGlobalSettings().DefaultDPIX; fParams.DpiY := IEGlobalSettings().DefaultDPIY; fParams.FreeColorMap; bg := TColor2TRGB(GetReBackground()); if meta.IsWmf() or meta.IsEmf() then begin // handle alpha channel manually bmp.Fill(CreateRGBA(0, 1, 2, 0)); // uses (0,1,2) as key color for transparent background bmp.IECanvas.Draw(meta, 0, 0, dstWidth, dstHeight); for i := 0 to dstHeight - 1 do begin px := bmp.ScanLine[i]; for j := 0 to dstWidth - 1 do begin if (px^.r = 0) and (px^.g = 1) and (px^.b = 2) then begin // this is the transparent background px^.r := bg.r; px^.g := bg.g; px^.b := bg.b; px^.a := 0; end else begin // this is the foreground px^.a := 255; end; inc(px); end; end; end else begin // direct draw on BGRA bitmap bmp.Fill(CreateRGBA(bg.r, bg.g, bg.b, 0)); bmp.IECanvas.Draw(meta, 0, 0, dstWidth, dstHeight); end; if WithAlpha then bmp.SynchronizeRGBA(true) else bmp.RemoveAlphaChannel(); bmp.PixelFormat := ie24RGB; fIEBitmap.Assign(bmp); finally bmp.Free(); end; Result := Not fAborting; Update(); ResetModified(); end; procedure TImageEnIO.ParamsFromMetaFile(stream: TStream); var meta: TMetaFile; begin meta := TMetaFile.Create; meta.LoadFromStream(stream); try fParams.FileName := ''; if meta.Enhanced then fParams.FileType := ioEMF else fParams.FileType := ioWMF; fParams.BitsPerSample := 8; fParams.SamplesPerPixel := 3; fParams.Width := meta.Width; fParams.Height := meta.Height; fParams.OriginalWidth := meta.Width; fParams.OriginalHeight := meta.Height; fParams.DpiX := IEGlobalSettings().DefaultDPIX; fParams.DpiY := IEGlobalSettings().DefaultDPIY; fParams.FreeColorMap; finally meta.Free; end; end; function TImageEnIO.ImportMetafile(const FileName: WideString; Width, Height: integer; WithAlpha: boolean): Boolean; var meta: TIEMetafile; begin // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateImportMetaFileRetBool(self, ImportMetaFile, FileName, Width, Height, WithAlpha); Result := True; exit; end; try meta := TIEMetaFile.Create(FileName); try Result := ImportMetaFile(meta, Width, Height, WithAlpha); fParams.FileName := FileName; finally FreeAndNil(meta); end; finally DoFinishWork; end; end; function TImageEnIO.ImportMetafile(Stream: TStream; Width: Integer = -1; Height: Integer = -1; WithAlpha: boolean = True): Boolean; var meta: TIEMetafile; begin try meta := TIEMetaFile.Create(Stream); try Result := ImportMetaFile(meta, Width, Height, WithAlpha); fParams.FileName := ''; finally FreeAndNil(meta); end; finally DoFinishWork; end; end; function TImageEnIO.ParamsFromFileOrStream(const FileName: WideString; Stream: TStream; Format: TIOFileType): Boolean; var idummy: integer; fpi: TIEFileFormatInfo; fs: TIEWideFileStream; NullProgress: TProgressRec; tempAlphaChannel: TIEMask; BufStream: TIEBufferedReadStream; bIsFile: Boolean; begin Result := True; fs := nil; BufStream := nil; bIsFile := Stream = nil; try if Format = ioUnknown then try if bIsFile then Format := FindFileFormat( FileName, ffFallbackToExtension ) else Format := FindStreamFormat(Stream); except // Unexpected error end; if Format = ioUnknown then begin fParams.FileType := ioUnknown; DoFinishWork; Result := False; exit; end; try fParams.FileType := Format; fParams.ResetInfo; fAborting := true; // So that fAborting is True if the file is not found NullProgress := NullProgressRec( fAborting, False ); tempAlphaChannel := nil; if bIsFile then begin fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); BufStream := TIEBufferedReadStream.Create(fs, 8192, IEGlobalSettings().UseRelativeStreams); end else begin BufStream := TIEBufferedReadStream.Create(Stream, 8192, IEGlobalSettings().UseRelativeStreams); end; fAborting := false; case fParams.FileType of ioTIFF: TIFFReadStream(fIEBitmap, BufStream, idummy, fParams, NullProgress, True, tempAlphaChannel, true, true, false, false); ioGIF: ReadGIFStream(BufStream, fIEBitmap, idummy, fParams, NullProgress, True, tempAlphaChannel, true); ioJPEG: ReadJpegStream(BufStream, nil, fIEBitmap, fParams, NullProgress, True, false, true, false, true, true, -1, fParams.IsNativePixelFormat); ioICO: ICOReadStream(BufStream, fIEBitmap, fParams, True, NullProgress, tempAlphaChannel, true); ioCUR: CURReadStream(BufStream, fIEBitmap, fParams, True, NullProgress, tempAlphaChannel, true); ioPCX: ReadPcxStream(BufStream, fIEBitmap, fParams, BufStream.size, NullProgress, True); ioDCX: IEDCXReadStream(BufStream, fIEBitmap, fParams, NullProgress, True); ioBMP: BMPReadStream(BufStream, fIEBitmap, BufStream.size, fParams, NullProgress, True, false, tempAlphaChannel, true); {$IFDEF IEINCLUDEPNG} ioPNG: ReadPNGStream(BufStream, fIEBitmap, fParams, NullProgress, true); {$ENDIF} {$ifdef IEINCLUDEDICOM} ioDICOM: IEDicomRead(BufStream, fParams, fIEBitmap, NullProgress, true); {$endif} ioTGA: ReadTGAStream(BufStream, fIEBitmap, fParams, NullProgress, true, tempAlphaChannel, true); ioPXM: PXMReadStream(BufStream, fIEBitmap, fParams, NullProgress, true); ioWBMP: WBMPReadStream(BufStream, fIEBitmap, fParams, NullProgress, true); {$IFDEF IEINCLUDEJPEG2000} ioJP2: J2KReadStream(BufStream, fIEBitmap, fParams, NullProgress, true); ioJ2K: J2KReadStream(BufStream, fIEBitmap, fParams, NullProgress, true); {$ENDIF} {$ifdef IEINCLUDERAWFORMATS} ioRAW: IEReadCameraRAWStream(BufStream, fIEBitmap, fParams, NullProgress, true); {$endif} {$ifdef IEINCLUDEPSD} ioPSD: IEReadPSD(BufStream, nil, fParams, NullProgress, false, nil); {$endif} {$ifdef IEINCLUDEWIC} ioHDP: if bIsFile then IEHDPRead(BufStream, fIEBitmap, fParams, NullProgress, true) else IEHDPRead(BufStream, nil, fParams, NullProgress, false); {$endif} ioWMF, ioEMF: ParamsFromMetaFile(BufStream); ioIEN: ParamsFromStreamIEN(BufStream); else begin fpi := IEFileFormatGetInfo(fParams.FileType); if assigned( fpi ) and assigned( fpi.ReadFunction ) then fpi.ReadFunction(BufStream, fIEBitmap, fParams, NullProgress, true) else Result := False; end; end; except on e:Exception do begin if e.message = IERS_IEVISIONNOTFOUND then raise; fParams.FileType := ioUnknown; Result := False; end; end; if fAborting then begin fParams.FileType := ioUnknown; Result := False; end; if bIsFile then fParams.FileName := FileName; finally FreeAndNil( BufStream ); FreeAndNil( fs ); end; DoFinishWork; end; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-16) function TImageEnIO.ParamsFromFileFormat(const FileName: WideString; Format: TIOFileType): Boolean; begin Result := ParamsFromFileOrStream( FileName, nil, Format ); end; {$endif} {!! TImageEnIO.ParamsFromFile Declaration function ParamsFromFile(const FileName: WideString; bUseExtension: Boolean = False): Boolean; overload; function ParamsFromFile(const FileName: WideString; Format: ): Boolean; overload; Description Reads the image properties without loading the image (and without changing the current image). Result is false if a loading error is encountered due to a corrupt or unknown image format. FileName is the file name with full path. Format is the file format that the stream or file contains. If ioUnknown is specified then the file content is analyzed to determine the format. bUseExtension determines that the file format is based on the extension of the file, e.g. image.jpeg will be processed as ioJPEG format. Examples // Load the parameters of an image (which may be a BMP file, but we will examine the content to be sure) ImageEnView1.IO.ParamsFromFile( 'C:\alfa.bmp' ); Label1.Caption := 'alfa.bmp has ' + inttostr(ImageEnView1.IO.Params.BitsPerSample) + ' bits per sample'; // Load the parameters of a BMP ImageEnView1.IO.ParamsFromFile( 'C:\alfa.bmp', ioBMP ); Label1.Caption := 'alfa.bmp has ' + inttostr(ImageEnView1.IO.Params.BitsPerSample) + ' bits per sample'; // Load the parameters of a file. It will be assumed to a BMP because of the file extension ImageEnView1.IO.ParamsFromFile( 'C:\alfa.bmp', True ); Label1.Caption := 'alfa.bmp has ' + inttostr(ImageEnView1.IO.Params.BitsPerSample) + ' bits per sample'; // Show the EXIF date of an image IO := TImageEnIO.Create( nil ); try IO.ParamsFromFile( sFilename ); ShowMessage( DateTimeToStr(( IO.IOParams.EXIF_DateTimeOriginal2 )); finally IO.Free; end; !!} function TImageEnIO.ParamsFromFile(const FileName: WideString; Format: TIOFileType): Boolean; begin Result := ParamsFromFileOrStream( FileName, nil, Format ); end; function TImageEnIO.ParamsFromFile(const FileName: WideString; bUseExtension: Boolean = False): Boolean; var Format: TIOFileType; begin Format := ioUnknown; if bUseExtension then Format := IEFilenameToFileFormat( FileName ); Result := ParamsFromFileOrStream( FileName, nil, Format ); end; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-16) function TImageEnIO.ParamsFromStreamFormat(Stream: TStream; format: TIOFileType): Boolean; begin Result := ParamsFromFileOrStream( '', Stream, Format ); end; {$endif} {!! TImageEnIO.ParamsFromStream Declaration function ParamsFromStream(Stream: TStream; Format: = ioUnknown): Boolean; Description Reads the image properties without loading the image (and without changing the current image). Result is false if a loading error is encountered due to a corrupt or unknown image format. Stream is a TStream that contains the image. Format is the file format that the stream or file contains. If ioUnknown is specified then the file content is analyzed to determine the format. !!} // Fills Params reading Stream, but doesn't load the image // format specifies the file format // The Stream position changes function TImageEnIO.ParamsFromStream(Stream: TStream; Format: TIOFileType = ioUnknown): Boolean; begin Result := ParamsFromFileOrStream( '', Stream, Format ); end; {!! TImageEnIO.ParamsFromBuffer Declaration function ParamsFromBuffer(Buffer: Pointer; BufferSize: Integer; Format: = ioUnknown): Boolean; Description Loads image parameters (but not the actual image) from the specified buffer. Result is false if a loading error is encountered due to a corrupt or non-standard image format. Parameter Description Buffer The buffer pointer BufferSize The buffer length in bytes. Format Specifies the expected file format. If Format is ioUnknown, then try to find the format automatically
See also:
Example ImageEnView1.IO.ParamsFromBuffer(mybuffer, mybufferlength, ioJPEG); !!} function TImageEnIO.ParamsFromBuffer(Buffer: Pointer; BufferSize: Integer; Format: TIOFileType): Boolean; var Stream: TIEMemStream; begin Result := False; if ( Buffer = nil ) or ( BufferSize = 0 ) then begin fAborting := true; exit; end; Stream := TIEMemStream.Create( Buffer, BufferSize ); try Result := ParamsFromStream( Stream, Format ); finally FreeAndNil( Stream ); end; end; function TImageEnIO.SyncLoadFromStreamPXM(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; PXMReadStream(Stream, fIEBitmap, fParams, Progress, false); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioPXM; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromFilePXM Declaration function LoadFromFilePXM(const FileName: WideString): Boolean; Description Loads an image from a PBM, PGM or PPM file. FileName is the file name including extension. Result will be false if the file is not a recognized file type (and will be false). Loading errors due to a file not being available will raise an exception. !!} function TImageEnIO.LoadFromFilePXM(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFilePXM, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamPXM( fs ); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamPXM Declaration function LoadFromStreamPXM(Stream: TStream): Boolean; Description Loads an image from a stream containing a PBM, PGM or PPM file. The result will be false if an error is encountered, e.g. the file in the stream is not a recognized format ( will be true). !!} function TImageEnIO.LoadFromStreamPXM(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamPXM, Stream); Result := True; end else begin Result := SyncLoadFromStreamPXM( Stream ); end; end; {!! TImageEnIO.SaveToFilePXM Declaration procedure SaveToFilePXM(const FileName: WideString); Description Saves the current image to a file in PBM, PGM or PPM format. FileName is the file name including extension. If the PBM (Portable Bitmap) contains only 1 bpp images (black/white), then the values must be Params.BitsPerPixel = 1 and Params.SamplesPerPixel = 1. If the PGM (Portable Graymap) contains only 8 bpp images (gray scale), then the values must be Params.BitsPerPixel = 8 and Params.SamplesPerPixel = 1. If the PPM (Portable Pixmap) contains only 24 bpp images (true color), then the values must be Params.BitsPerPixel = 8 and Params.SamplesPerPixel = 3. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. !!} procedure TImageEnIO.SaveToFilePXM(const FileName: WideString); var Progress: TProgressRec; fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFilePXM, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) and (fIEBitmap.PixelFormat<>ie48RGB) then fIEBitmap.PixelFormat := ie24RGB; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try PXMWriteStream(fs, fIEBitmap, fParams, Progress); fParams.FileName := FileName; fParams.FileType := ioPXM; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamPXM Declaration procedure SaveToStreamPXM(Stream: TStream); Description Saves the current image to a stream in PBM, PGM or PPM format. If the PBM (Portable Bitmap) contains only 1 bpp images (black/white), then the values must be Params.BitsPerPixel=1 and Params.SamplesPerPixel=1. If the PGM (Portable Graymap) contains only 8 bpp images (gray scale), then the values must be Params.BitsPerPixel=8 and Params.SamplesPerPixel=1. If the PPM (Portable Pixmap) contains only 24 bpp images (true color), then the values must be Params.BitsPerPixel=8 and Params.SamplesPerPixel=3. !!} procedure TImageEnIO.SaveToStreamPXM(Stream: TStream); var Progress: TProgressRec; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamPXM, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; PXMWriteStream(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; procedure PrintImagePos_func1(x, y: dword; pixel: pointer; UserData: pointer); begin with PRGB(pixel)^ do begin r := pbytearray(UserData)^[r]; g := pbytearray(UserData)^[g]; b := pbytearray(UserData)^[b]; end; end; // Creates fPrintBitmap, optionally drawing annotations and layers // Note: must free fPrintBitmap procedure TImageEnIO.GeneratePrintBitmap(PrintAnnotations, PrintLayers: Boolean); const Antialias_Annot = True; // Objects are merged with anti-aliasing var iev: TImageEnView; wasBG: TColor; begin FreeAndNil( fPrintBitmap ); fPrintBitmap := TIEBitmap.Create(); iev := nil; if assigned( fImageEnView ) and ( fImageEnView is TImageEnView ) then iev := TImageEnView( fImageEnView ); // Layers if PrintLayers and assigned( iev ) and ( iev.LayersCount > 1 ) then begin // Ensure transparency is printed white wasBG := iev.Background; iev.Background := clWhite; iev.LayersSaveMergedTo( fPrintBitmap ); iev.Background := wasBG; end else fPrintBitmap.Assign( fIEBitmap ); // Annotations if PrintAnnotations then begin {$ifdef IEINCLUDEIMAGINGANNOT} if GetParams.ImagingAnnot.ObjectsCount > 0 then GetParams.ImagingAnnot.DrawToBitmap( fPrintBitmap, Antialias_Annot ) else {$endif} if GetParams.ImageEnAnnot.IsEmpty = False then GetParams.ImageEnAnnot.DrawToBitmap( fPrintBitmap, Antialias_Annot ); end; end; // dpix, dpiy cannot be 0 procedure TImageEnIO.PrintImagePosEx(PrintBMP: TIEBitmap; PrtCanvas: TCanvas; dpix, dpiy: integer; x, y: double; Width, Height: double; GammaCorrection: double); var px, py, pWidth, pHeight: integer; zz: double; begin IEPrintLogWrite('TImageEnIO.PrintImagePosEx: begin'); px := trunc(x * dpix); py := trunc(y * dpiy); pWidth := trunc(Width * dpix); pHeight := trunc(Height * dpiy); zz := pWidth / PrintBMP.Width; // if ( fPrintingFilterOnSubsampling <> rfNone ) and ( zz < 1 ) then begin IEPrintLogWrite('TImageEnIO.PrintImagePosEx: calling RenderToCanvas with subsampling filter'); PrintBMP.RenderToCanvas(PrtCanvas, px, py, pWidth, pHeight, fPrintingFilterOnSubsampling, GammaCorrection); end else begin IEPrintLogWrite('TImageEnIO.PrintImagePosEx: calling RenderToCanvas without subsampling filter'); PrintBMP.RenderToCanvas(PrtCanvas, px, py, pWidth, pHeight, rfNone, GammaCorrection); end; IEPrintLogWrite('TImageEnIO.PrintImagePosEx: end'); end; {!! TImageEnIO.PrintImagePos Declaration procedure PrintImagePos(PrtCanvas: TCanvas; x, y: double; Width, Height: double; GammaCorrection: double = 1; PrintAnnotations: Boolean = False; PrintLayers: Boolean = False); Description Prints the current image at a specified absolute position and size. Parameter Description PrtCanvas The canvas to bring to. Specify nil to use Printer.Canvas FC>x, y Top-left starting point in inches FC>Width, Height Printed image size in inches. GammaCorrection The gamma correction value (Specify 1.0 to disable gamma correction) FC>PrintAnnotations If true and the image contains imaging or ImageEn annotations they will be printed FC>PrintLayers If true and the attached image contains multiple layers, they will be printed. If False, only the image (i.e. current layer) is printed
Example // Add Printers unit to your uses clause... uses Printers; // print the image two inches from the top and left of the page, and at a width and height of 10 inches (the image will be stretched) Printer.BeginDoc; ImageEnView1.IO.PrintImagePos( Printer.Canvas, 2, 2, 10, 10 ); Printer.EndDoc; !!} // if width = 0 and/or height = 0, PrintImagePos autocalculates for normal size procedure TImageEnIO.PrintImagePos(PrtCanvas: TCanvas; x, y: double; Width, Height: double; GammaCorrection: double; PrintAnnotations: Boolean; PrintLayers: Boolean); var dpix, dpiy: integer; begin if not MakeConsistentBitmap([]) then exit; if PrtCanvas = nil then PrtCanvas := Printer.Canvas; GeneratePrintBitmap( PrintAnnotations, PrintLayers ); dpix := GetDeviceCaps(PrtCanvas.Handle, LOGPIXELSX); dpiy := GetDeviceCaps(PrtCanvas.Handle, LOGPIXELSY); PrintImagePosEx( fPrintBitmap, PrtCanvas, dpix, dpiy, x, y, Width, Height, GammaCorrection ); FreeAndNil( fPrintBitmap ); end; // dpix, dpiy are dpi of destination device, cannot be 0 // bPrinting = True when printing, False when previewing procedure TImageEnIO.PrintImageEx(PrintBMP: TIEBitmap; PrtCanvas: TCanvas; dpix, dpiy: integer; pagewidth, pageheight: double; MarginLeft, MarginTop, MarginRight, MarginBottom: double; VerticalPos: TIEVerticalPos; HorizontalPos: TIEHorizontalPos; Size: TIESize; SpecWidth, SpecHeight: double; GammaCorrection: double; bPrinting: Boolean = True); var x, y, width, height: double; z: double; bitmapwidth, bitmapheight: double; // in inches imgdpix, imgdpiy: integer; PageCountX, PageCountY: Integer; aPrintBmp : TIEBitmap; PrintX, PrintY, OutX, OutY, OutWidth, OutHeight: Double; ipx, ipy: Integer; begin IEPrintLogWrite('TImageEnIO.PrintImageEx: begin'); if PrtCanvas = nil then PrtCanvas := Printer.Canvas; if dpix = -1 then dpix := GetDeviceCaps(PrtCanvas.Handle, LOGPIXELSX); if dpiy = -1 then dpiy := GetDeviceCaps(PrtCanvas.Handle, LOGPIXELSY); if pagewidth = -1 then pagewidth := GetDeviceCaps(PrtCanvas.Handle, HORZRES) / dpix; if pageheight = -1 then pageheight := GetDeviceCaps(PrtCanvas.Handle, VERTRES) / dpiy; imgdpix := Params.DpiX; if imgdpix <= 1 then imgdpix := dpix; imgdpiy := Params.DpiY; if imgdpiy <= 1 then imgdpiy := dpiy; IEPrintLogWrite('TImageEnIO.PrintImageEx: setting page sizes'); pagewidth := pagewidth - (MarginLeft + MarginRight); pageheight := pageheight - (MarginTop + MarginBottom); width := 0; height := 0; x := 0; y := 0; z := 1; PageCountX := 1; PageCountY := 1; case Size of iesNormal: begin width := PrintBMP.Width / imgdpix; height := PrintBMP.Height / imgdpiy; end; iesFitToPage: begin bitmapwidth := PrintBMP.Width / dpix; bitmapheight := PrintBMP.Height / dpiy; z := dmin(pagewidth / bitmapwidth, pageheight / bitmapheight); width := bitmapwidth * z; height := bitmapheight * z; end; iesFitToPageStretch: begin width := pagewidth; height := pageheight; end; iesFillPage: begin bitmapwidth := PrintBMP.Width / dpix; bitmapheight := PrintBMP.Height / dpiy; z := dmax(pagewidth / bitmapwidth, pageheight / bitmapheight); width := bitmapwidth * z; height := bitmapheight * z; end; iesSpecifiedSize: begin width := SpecWidth; height := SpecHeight; end; iesMultiplePages: begin bitmapwidth := PrintBMP.Width / dpix; bitmapheight := PrintBMP.Height / dpiy; z := dmin( Trunc( SpecWidth ) * PageWidth / bitmapwidth, Trunc( SpecHeight ) * pageheight / bitmapheight); width := bitmapwidth * z; height := bitmapheight * z; PageCountX := round( Width / PageWidth + 0.49999 ); // Not ceil(). We don't want that much accuracy PageCountY := round( Height / PageHeight + 0.49999 ); end; end; case HorizontalPos of iehpLEFT: x := 0; iehpCENTER: x := (PageCountX * pagewidth - width) / 2; iehpRIGHT: x := PageCountX * pagewidth - width; end; case VerticalPos of ievpTOP: y := 0; ievpCenter: y := (PageCountY * pageheight - height) / 2; ievpBOTTOM: y := PageCountY * pageheight - height; end; if Size <> iesMultiplePages then PrintImagePosEx( PrintBMP, PrtCanvas, dpix, dpiy, MarginLeft + x, MarginTop + y, width, height, GammaCorrection ) else begin aPrintBmp := TIEBitmap.create; aPrintBmp.PixelFormat := PrintBMP.PixelFormat; try OutY := 0; for ipy := 0 to PageCountY - 1 do begin if ipy = 0 then begin PrintY := Y; OutHeight := PageHeight - Y; end else begin PrintY := 0; OutHeight := PageHeight; end; if OutY + OutHeight > Height then OutHeight := Height - OutY; OutX := 0; for ipx := 0 to PageCountX - 1 do begin if ipx = 0 then begin PrintX := X; OutWidth := PageWidth - X; end else begin PrintX := 0; OutWidth := PageWidth; end; if OutX + OutWidth > Width then OutWidth := Width - OutX; aPrintBmp.Width := Trunc( OutWidth * dpix / z ); aPrintBmp.Height := Trunc( OutHeight * dpiy / z ); PrintBMP.CopyRectTo( aPrintBmp, Trunc( OutX * dpix / z ), Trunc( OutY * dpiy / z ), 0, 0, aPrintBmp.Width, aPrintBmp.Height, false ); if bPrinting and ( ipx + ipy > 0 ) then Printer.NewPage; PrintImagePosEx( aPrintBmp, PrtCanvas, dpix, dpiy, MarginLeft + PrintX, MarginTop + PrintY, OutWidth, OutHeight, GammaCorrection ); OutX := OutX + OutWidth; if bPrinting = False then exit; // Just show first page end; OutY := OutY + OutHeight; end; finally aPrintBmp.Free; end; end; IEPrintLogWrite('TImageEnIO.PrintImageEx: end'); end; {!! TImageEnIO.PrintImage Declaration procedure PrintImage(PrtCanvas: TCanvas = nil; MarginLeft: double = 1; MarginTop: double = 1; MarginRight: double = 1; MarginBottom: double = 1; VerticalPos: = ievpCenter; HorizontalPos: = iehpCENTER; Size: = iesFitToPage; SpecWidth: double = 0; SpecHeight: double = 0; GammaCorrection: double = 1; PrintAnnotations: Boolean = False; PrintLayers: Boolean = False); Description Print the current image by specifying margins, vertical position, horizontal position and size. Parameter Description PrtCanvas The canvas to bring to. Specify nil to use Printer.Canvas MarginLeft Left page margin in inches (Specify zero for no margin) MarginTop Top page margin in inches (Specify zero for no margin) MarginRight Right page margin in inches (Specify zero for no margin) MarginBottom Bottom page margin in inches (Specify zero for no margin) VerticalPos How the image is vertically aligned on the page HorizontalPos How the image horizontally aligned on the page Size How the image should be sized for printing SpecWidth The absolute width of the image in inches if Size = iesSpecifiedSize. The number of pages wide if Size = iesMultiplePages SpecHeight The absolute height of the image in inches if Size = iesSpecifiedSize. The number of pages high if Size = iesMultiplePages GammaCorrection The gamma correction value (Specify 1.0 to disable gamma correction) FC>PrintAnnotations If true and the image contains imaging or ImageEn annotations they will be printed FC>PrintLayers If true and the attached image contains multiple layers, they will be printed. If False, only the image (i.e. current layer) is printed
Demo Demos\FullApps\PhotoEn3\ImageEx.dpr Example // Add Printers unit to your uses clause... uses Printers; // Print the image in the center of the page at the original size Printer.BeginDoc; ImageEnView1.IO.PrintImage( Printer.Canvas, 0, 0, 0, 0, ievpCenter, iehpCenter, iesNormal ); Printer.EndDoc; // Print the image in the center of the page stretched to page dimensions (respecting the proportions) Printer.BeginDoc; ImageEnView1.IO.PrintImage( Printer.Canvas, 0, 0, 0, 0, ievpCenter, iehpCenter, iesFitToPage ); Printer.EndDoc; // Print the image as a poster, four pages wide and six pages high Printer.BeginDoc; ImageEnView1.IO.PrintImage( Printer.Canvas, 0, 0, 0, 0, ievpCenter, iehpCenter, iesMultiplePages, 4, 6, 1 ); Printer.EndDoc; // Print all pages of a TIFF Printer.BeginDoc; for I := 0 to ImageEnView1.IO.Params.ImageCount - 1 do begin ImageEnView1.IO.Params.ImageIndex := I; ImageEnView1.IO.LoadFromFile( 'C:\input.tif' ); ImageEnView1.IO.PrintImage(); end; Printer.EndDoc; // Print the image in the center with layers Printer.BeginDoc; ImageEnView1.IO.PrintImage( Printer.Canvas, 0, 0, 0, 0, ievpCenter, iehpCenter, iesNormal, 0, 0, 1, False, True ); Printer.EndDoc; !!} procedure TImageEnIO.PrintImage(PrtCanvas: TCanvas; MarginLeft, MarginTop, MarginRight, MarginBottom: double; VerticalPos: TIEVerticalPos; HorizontalPos: TIEHorizontalPos; Size: TIESize; SpecWidth, SpecHeight: double; GammaCorrection: double; PrintAnnotations: Boolean; PrintLayers: Boolean); begin IEPrintLogWrite('TImageEnIO.PrintImage: begin'); if not MakeConsistentBitmap([]) then exit; if assigned(fTImage) then begin if (fTImage.Picture.Bitmap.PixelFormat <> pf1bit) and (fTImage.Picture.Bitmap.PixelFormat <> pf24bit) then fTImage.Picture.Bitmap.PixelFormat := pf24bit; end; GeneratePrintBitmap( PrintAnnotations, PrintLayers ); PrintImageEx( fPrintBitmap, PrtCanvas, -1, -1, -1, -1, MarginLeft, MarginTop, MarginRight, MarginBottom, VerticalPos, HorizontalPos, Size, SpecWidth, SpecHeight, GammaCorrection, True); FreeAndNil( fPrintBitmap ); IEPrintLogWrite('TImageEnIO.PrintImage: end'); end; {!! TImageEnIO.PreviewPrintImage Declaration procedure PreviewPrintImage(DestBitmap: TBitmap; MaxBitmapWidth: Integer; MaxBitmapHeight: Integer; PrinterObj: TPrinter = nil; MarginLeft: Double = 1; MarginTop: Double = 1; MarginRight: Double = 1; MarginBottom: Double = 1; VerticalPos: = ievpCenter; HorizontalPos: = iehpCenter; Size: = iesFitToPage; SpecWidth: Double = 0; SpecHeight: Double = 0; GammaCorrection: Double = 1); Description Draws a preview of the printing of the current image by specifying margins, vertical position, horizontal position and size. It also paints a rectangle over the image to show the margin limits. Parameter Description DestBitmap Destination bitmap where to paint the preview. Resizes DestBitmap as needed. MaxBitmapWidth Maximum destination bitmap width. Preview will be stretched to match this size. MaxBitmapHeight Maximum destination bitmap height. Preview will be stretched to match this size. Printer This is the Printer object. PreviewPrintImage need it to know printer settings as orientation or page sizes. MarginLeft Left page margin in inches. Specying zero causes no margin to be used. MarginTop Top page margin in inches. Specying zero causes no margin to be used. MarginRight Right page margin in inches. Specying zero causes no margin to be used. MarginBottom Bottom page margin in inches. Specying zero causes no margin to be used. VerticalPos Determines how the image vertically aligns within the page. HorizontalPos Determines how the image horizontally aligns within the page. Size How the image should be sized for printing SpecWidth The absolute width of the image in inches if Size = iesSpecifiedSize. The number of pages wide if Size = iesMultiplePages SpecHeight The absolute height of the image in inches if Size = iesSpecifiedSize. The number of pages high if Size = iesMultiplePages GammaCorrection The gamma correction value, use 1.0 to disable gamma correction.
Example // Paint and display the preview in ImageEnView2 component. ImageEnView1.IO.PreviewPrintImage(ImageEnView2.Bitmap, ImageEnView2.Width, ImageEnView2.Height, Printer, 0, 0, 0, 0, ievpCenter, iehpCenter, iesFitToPage , 0 , 0 , 1); ImageEnView2.Update; !!} procedure TImageEnIO.PreviewPrintImage(DestBitmap: TBitmap; MaxBitmapWidth, MaxBitmapHeight: integer; PrinterObj: TPrinter; MarginLeft, MarginTop, MarginRight, MarginBottom: double; VerticalPos: TIEVerticalPos; HorizontalPos: TIEHorizontalPos; Size: TIESize; SpecWidth, SpecHeight: double; GammaCorrection: double); begin if not MakeConsistentBitmap([]) then exit; if assigned(fTImage) then begin if (fTImage.Picture.Bitmap.PixelFormat <> pf1bit) and (fTImage.Picture.Bitmap.PixelFormat <> pf24bit) then fTImage.Picture.Bitmap.PixelFormat := pf24bit; end; PreviewPrintImageEx( fIEBitmap, DestBitmap, MaxBitmapWidth, MaxBitmapHeight, PrinterObj, MarginLeft, MarginTop, MarginRight, MarginBottom, VerticalPos, HorizontalPos, Size, SpecWidth, SpecHeight, GammaCorrection ); end; procedure TImageEnIO.PreviewPrintImageEx(PrintBMP: TIEBitmap; DestBitmap: TBitmap; MaxBitmapWidth, MaxBitmapHeight: integer; PrinterObj: TPrinter; MarginLeft, MarginTop, MarginRight, MarginBottom: double; VerticalPos: TIEVerticalPos; HorizontalPos: TIEHorizontalPos; Size: TIESize; SpecWidth, SpecHeight: double; GammaCorrection: double); var Zoom, z1, z: double; x1, y1, x2, y2: integer; dpix, dpiy: integer; PageWidth, PageHeight: integer; begin if PrinterObj = nil then PrinterObj := Printer; Zoom := (MaxBitmapWidth - 5) / (PrinterObj.PageWidth / 100); z1 := (MaxBitmapHeight - 5) / (PrinterObj.PageHeight / 100); if z1 < Zoom then Zoom := z1; z := Zoom / 100; PageWidth := trunc(PrinterObj.PageWidth * z); PageHeight := trunc(PrinterObj.PageHeight * z); dpix := trunc(GetDeviceCaps(PrinterObj.Handle, LOGPIXELSX) * z); dpiy := trunc(GetDeviceCaps(PrinterObj.Handle, LOGPIXELSY) * z); DestBitmap.Width := 1; DestBitmap.Height := 1; DestBitmap.PixelFormat := pf24bit; DestBitmap.Width := PageWidth; DestBitmap.Height := PageHeight; with DestBitmap.Canvas do begin Brush.Color := clWhite; Brush.Style := bsSolid; fillrect(rect(0, 0, destbitmap.width, destbitmap.height)); end; if (dpix <= 0) or (dpiy <= 0) then exit; PrintImageEx( PrintBMP, DestBitmap.Canvas, dpix, dpiy, PageWidth / dpix, PageHeight / dpiy, MarginLeft, MarginTop, MarginRight, MarginBottom, VerticalPos, HorizontalPos, Size, SpecWidth, SpecHeight, GammaCorrection, False); with DestBitmap.Canvas do begin Brush.Style := bsClear; Pen.Color := IEPrint_Preview_Margin_Color; Pen.Style := psDot; Pen.Width := 1; x1 := trunc(MarginLeft * dpix); y1 := trunc(MarginTop * dpiy); x2 := trunc(PageWidth - MarginRight * dpix); y2 := trunc(PageHeight - MarginBOttom * dpiy); Rectangle(x1, y1, x2, y2); end; end; {!! TImageEnIO.InjectJpegIPTC Declaration function InjectJpegIPTC(const FileName: WideString): Boolean; Description Replaces the IPTC information in the specified JPEG file with the current IPTC (in
) without loading or modifying the original image. The method returns False if the operation could not be performed. Example // copy the IPTC info (not the image) from file one.jpg to the inside of file two.jpg, without loading any images ImageEnView1.IO.ParamsFromFile('D:\one.jpg'); ImageEnView1.IO.InjectJpegIPTC('D:\two.jpg'); // removes IPTC info from image.jpg ImageEnView1.IO.Params.IPTC_Info.Clear; ImageEnView1.IO.InjectJpegIPTC('D:\image.jpg'); !!} function TImageEnIO.InjectJpegIPTC(const FileName: WideString): boolean; var fr: TMemoryStream; fm: TMemoryStream; Progress: TProgressRec; begin fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); fr := TMemorystream.Create; fm := TMemoryStream.Create; try fr.LoadFromFile(FileName); fr.Position := 0; fm.Size := fr.Size; result := IEJpegInjectIPTC(fr, fm, fParams.IPTC_Info, Progress); fm.Size := fm.Position; if result then fm.SaveToFile(FileName); finally FreeAndNil(fr); FreeAndNil(fm); DoFinishWork; end; end; {!! TImageEnIO.InjectJpegIPTCStream Declaration function InjectJpegIPTCStream(InputStream, OutputStream: TStream): Boolean; Description Replaces the IPTC information of the JPEG file in the InputStream stream with the current IPTC (in ) without loading or modifying the original image. OutputStream contains the modified stream. The method returns False if the operation could not be performed. !!} function TImageEnIO.InjectJpegIPTCStream(InputStream, OutputStream: TStream): boolean; var Progress: TProgressRec; begin Progress.fOnProgress := nil; result := IEJpegInjectIPTC(InputStream, OutputStream, fParams.IPTC_Info, Progress); end; {!! TImageEnIO.InjectJpegEXIF Declaration function InjectJpegEXIF(const FileName: WideString): Boolean; Description Replaces the EXIF information in the specified JPEG file with the current EXIF (in ) without loading or modifying the original image. The method returns False if the operation could not be performed. Example // copy the EXIF info (not the image) from file one.jpg inside two.jpg, without loading any image ImageEnView1.IO.ParamsFromFile('D:\one.jpg'); ImageEnView1.IO.InjectJpegEXIF('D:\two.jpg'); // removes EXIF info from image.jpg ImageEnView1.IO.Params.EXIF_HasExifData := false; ImageEnView1.IO.InjectJpegEXIF('D:\image.jpg'); !!} function TImageEnIO.InjectJpegEXIF(const FileName: WideString): boolean; var fr: TMemoryStream; fm: TMemoryStream; Progress: TProgressRec; begin fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); fr := TMemoryStream.Create; fm := TMemoryStream.Create; try fr.LoadFromFile(FileName); fr.Position := 0; fm.Size := fr.Size; result := IEJpegInjectEXIF(fr, fm, fParams, Progress); fm.Size := fm.Position; if result then fm.SaveToFile(FileName); finally FreeAndNil(fr); FreeAndNil(fm); DoFinishWork; end; end; {!! TImageEnIO.InjectJpegEXIFStream Declaration function InjectJpegEXIFStream(InputStream, OutputStream: TStream): Boolean; Description Replaces the EXIF information in the JPEG file in InputStream stream with the current EXIF (in ) without loading or modifying the original image. OutputStream contains the modified stream. The method returns False if the operation could not be performed. !!} function TImageEnIO.InjectJpegEXIFStream(InputStream, OutputStream: TStream): boolean; var Progress: TProgressRec; begin Progress.fOnProgress := nil; result := IEJpegInjectEXIF(InputStream, OutputStream, fParams, Progress); end; {!! TImageEnIO.InjectTIFFEXIF Declaration function InjectTIFFEXIF(const FileName: WideString; pageIndex: Integer): boolean; function InjectTIFFEXIF(const InputFileName, OutputFileName: WideString; pageIndex: Integer): boolean; function InjectTIFFEXIF(InputStream, OutputStream: TStream; pageIndex: Integer): boolean; Description Replaces the EXIF information in the specified TIFF or InputStream stream with the current EXIF (in ) without loading or modifying the original image. OutputStream contains the modified stream. The method returns false if the operation could not be performed. Note: InjectTIFFEXIF works only with TIFF and Microsoft HD Photo file formats. !!} {$ifdef IEINCLUDETIFFHANDLER} function TImageEnIO.InjectTIFFEXIF(const FileName: WideString; pageIndex: Integer): boolean; begin result := IEInjectTIFFEXIF(nil, nil, FileName, FileName, pageIndex, fParams); end; function TImageEnIO.InjectTIFFEXIF(const InputFileName, OutputFileName: WideString; pageIndex: Integer = 0): boolean; begin result := IEInjectTIFFEXIF(nil, nil, InputFileName, OutputFileName, pageIndex, fParams); end; function TImageEnIO.InjectTIFFEXIF(InputStream, OutputStream: TStream; pageIndex: Integer): boolean; begin result := IEInjectTIFFEXIF(InputStream, OutputStream, '', '', pageIndex, fParams); end; {$endif} {$IFDEF IEINCLUDEOPENSAVEDIALOGS} {!! TImageEnIO.ExecuteOpenDialog Declaration function ExecuteOpenDialog(const InitialDir : WideString = ''; const InitialFileName : WideString = ''; AlwaysAnimate : boolean = False; FilterIndex: Integer = 0; const ExtendedFilters : WideString = ''; const Title : WideString = ''; const Filter : WideString = ''; DefaultFilter : = -1; LimitToFileType : = -1) : WideString; overload; function ExecuteOpenDialog(const Title : WideString; DefaultFilter : ; LimitToFileType : = -1; AlwaysAnimate : boolean = False) : WideString; overload; Description Executes the open dialog allowing the user to browse for an image file. It encapsulates the component. Parameter Description InitialDir Folder displayed on opening (leave as '' for no default) InitialFileName Default file name with extension (leave as '' for no default) AlwaysAnimate Enable to animate GIF and AVI (without user needing to click the play button). Default is False FilterIndex The index of the default selected item in the filter. Default is 0. Note: While this can change the first five items are generally: 1: Common graphics formats 2: All Graphics formats 3: JPEG 4: TIFF 5: GIF However, it is generally safer to use the DefaultFilter parameter instead ExtendedFilters Any additional file formats to add to the filter (example: 'Fun Bitmap|*.fun;*.fan') Title The dialog title. If unspecified the Windows default title is used Filter Override the default filter with a custom one (e.g. 'JPEG Image (JPG)|*.jpg|GIF Image (GIF)|*.gif') DefaultFilter Specify the file type that is displayed by default. This setting overrides FilterIndex, but is ignored if you have specified InitialFileName. Default is -1 LimitToFileType Limits the filter to a specified ImageEn file type, plus "All Supported Types" and "All Files" (only relevant if Filter is not set). Default is -1
Returns a null string ('') if the user clicks Cancel. Examples // Prompt to load a file into an ImageEnView sFilename := ImageEnView1.IO.ExecuteOpenDialog; if sFilename <> '' then ImageEnView1.IO.LoadFromFile(sFileName); // Prompt to load an image, defaulting to JPEG format (second overloaded method) sFilename := ImageEnView1.IO.ExecuteOpenDialog('Select an Image', ioJPEG); if sFilename <> '' then ImageEnView1.IO.LoadFromFile(sFileName); // Prompt to load an image, forcing GIF format (second overloaded method) sFilename := ImageEnView1.IO.ExecuteOpenDialog('Select an Image', -1, ioGIF); if sFilename <> '' then ImageEnView1.IO.LoadFromFile(sFileName); !!} function TImageEnIO.ExecuteOpenDialog(const Title : WideString; DefaultFilter : TIOFileType; LimitToFileType : TIOFileType = -1; AlwaysAnimate : boolean = False) : WideString; begin Result := ExecuteOpenDialog('', '', AlwaysAnimate, 0, '', Title, '', DefaultFilter, LimitToFileType); end; function TImageEnIO.ExecuteOpenDialog(const InitialDir : WideString = ''; const InitialFileName : WideString = ''; AlwaysAnimate : boolean = False; FilterIndex: Integer = 0; const ExtendedFilters : WideString = ''; const Title : WideString = ''; const Filter : WideString = ''; DefaultFilter : TIOFileType = -1; LimitToFileType : TIOFileType = -1) : WideString; var fOpenImageEnDialog: TOpenImageEnDialog; begin result := ''; fOpenImageEnDialog := TOpenImageEnDialog.Create(self); try fOpenImageEnDialog.InitialDir := string(InitialDir); fOpenImageEnDialog.FileName := InitialFileName; {$IFDEF IEINCLUDEMULTIVIEW} fOpenImageEnDialog.AlwaysAnimate := AlwaysAnimate; {$ENDIF} fOpenImageEnDialog.Options := fOpenImageEnDialog.Options + [OFENABLESIZING]; if Filter <> '' then begin fOpenImageEnDialog.AutoSetFilter := false; fOpenImageEnDialog.Filter := Filter; end; fOpenImageEnDialog.AutoSetFilterFileType := LimitToFileType; fOpenImageEnDialog.FilterDefault := DefaultFilter; fOpenImageEnDialog.FilterIndex := FilterIndex; fOpenImageEnDialog.AutoAdjustDPI := AutoAdjustDPI; fOpenImageEnDialog.FilteredAdjustDPI := FilteredAdjustDPI; fOpenImageEnDialog.ExtendedFilters := string(ExtendedFilters); if Title<>'' then fOpenImageEnDialog.Title := string(Title); if fOpenImageEnDialog.Execute then begin Params.ImageIndex := fOpenImageEnDialog.SelectedFrame; result := fOpenImageEnDialog.FileNameW; end; finally FreeAndNil(fOpenImageEnDialog); end; end; {$ENDIF} // IEINCLUDEOPENSAVEDIALOGS {$IFDEF IEINCLUDEOPENSAVEDIALOGS} {!! TImageEnIO.ExecuteSaveDialog Declaration function ExecuteSaveDialog(const InitialDir : WideString = ''; const InitialFileName : WideString = ''; AlwaysAnimate : boolean = False; FilterIndex: Integer = 0; const ExtendedFilters : WideString = ''; const Title : WideString = ''; const Filter : WideString = ''; DefaultFilter :
= -1; LimitToFileType : = -1) : WideString;overload; function ExecuteSaveDialog(const Title : WideString; DefaultFilter : ; LimitToFileType : = -1; AlwaysAnimate : boolean = False) : WideString; overload; Description Executes the save dialog allowing the user to specify a save filename. It encapsulates the component. Parameter Description InitialDir Folder displayed on opening (leave as '' for no default) InitialFileName Default file name with extension (leave as '' for no default) AlwaysAnimate Enable to animate GIF and AVI (without user needing to click the play button). Default is False FilterIndex The index of the default selected item in the filter. Default is 0. Note: While this can change the first five items are generally: 1: Common graphics formats 2: All Graphics formats 3: JPEG 4: TIFF 5: GIF However, it is generally safer to use the DefaultFilter parameter instead ExtendedFilters Any additional file formats to add to the filter (example: 'Fun Bitmap|*.fun;*.fan') Title The dialog title. If unspecified the Windows default title is used Filter Override the default filter with a custom one (e.g. 'JPEG Image (JPG)|*.jpg|GIF Image (GIF)|*.gif') DefaultFilter Specify the file type that is displayed by default. This setting overrides FilterIndex, but is ignored if you have specified InitialFileName. Default is -1 LimitToFileType Limits the filter to a specified ImageEn file type. Default is -1
Returns a null string ('') if the user clicks Cancel. Examples // Prompt to save a file in an ImageEnView sFilename := ImageEnView1.IO.ExecuteSaveDialog; if sFilename <> '' then ImageEnView1.IO.SaveToFile(sFileName) // Prompt to save an image, defaulting to JPEG format (second overloaded method) sFilename := ImageEnView1.IO.ExecuteOpenDialog('Save your Image', ioJPEG); if sFilename <> '' then ImageEnView1.IO.SaveToFile(sFileName) // Prompt to save an image, forcing GIF format (second overloaded method) sFilename := ImageEnView1.IO.ExecuteOpenDialog('Save your Image', -1, ioGIF); if sFilename <> '' then ImageEnView1.IO.SaveToFile(sFileName) !!} function TImageEnIO.ExecuteSaveDialog(const Title : WideString; DefaultFilter : TIOFileType; LimitToFileType : TIOFileType = -1; AlwaysAnimate : boolean = False) : WideString; begin Result := ExecuteSaveDialog('', '', AlwaysAnimate, 0, '', Title, '', DefaultFilter, LimitToFileType); end; function TImageEnIO.ExecuteSaveDialog(const InitialDir : WideString = ''; const InitialFileName : WideString = ''; AlwaysAnimate : boolean = False; FilterIndex: Integer = 0; const ExtendedFilters : WideString = ''; const Title : WideString = ''; const Filter : WideString = ''; DefaultFilter : TIOFileType = -1; LimitToFileType : TIOFileType = -1) : WideString; var fSaveImageEnDialog: TSaveImageEnDialog; begin result := ''; fSaveImageEnDialog := TSaveImageEnDialog.create(self); try fSaveImageEnDialog.InitialDir := string(InitialDir); fSaveImageEnDialog.FileName := InitialFileName; {$IFDEF IEINCLUDEMULTIVIEW} fSaveImageEnDialog.AlwaysAnimate := AlwaysAnimate; {$ENDIF} fSaveImageEnDialog.Options := fSaveImageEnDialog.Options + [OFENABLESIZING]; if Filter<>'' then begin fSaveImageEnDialog.AutoSetFilter := false; fSaveImageEnDialog.Filter := Filter; end; fSaveImageEnDialog.AutoSetFilterFileType := LimitToFileType; fSaveImageEnDialog.FilterDefault := DefaultFilter; fSaveImageEnDialog.AttachedImageEnIO := self; fSaveImageEnDialog.FilterIndex := FilterIndex; fSaveImageEnDialog.AutoAdjustDPI := AutoAdjustDPI; fSaveImageEnDialog.FilteredAdjustDPI := FilteredAdjustDPI; fSaveImageEnDialog.ExtendedFilters := string(ExtendedFilters); fSaveImageEnDialog.ShowFormats := iesfImagesOnly; if Title<>'' then fSaveImageEnDialog.Title := string(Title); if fSaveImageEnDialog.Execute then result := fSaveImageEnDialog.FileNameW; finally FreeAndNil(fSaveImageEnDialog); end; end; {$ENDIF} // IEINCLUDEOPENSAVEDIALOGS {!! TImageEnIO.CaptureFromScreen Declaration procedure CaptureFromScreen(Source:
; MouseCursor: TCursor = -1); Description Captures the current desktop or active window. MouseCursor defines the cursor to draw because ImageEn cannot get it from Windows. Use -1 for none. Example // Save the current desktop to 'screen.png' ImageEnView1.io.CaptureFromScreen(iecsScreen, -1); ImageEnView1.io.SaveToFile('D:\screen.png'); !!} procedure TImageEnIO.CaptureFromScreen(Source: TIECSSource; MouseCursor: TCursor); var hwin, hdc: THandle; x, y, w, h: integer; rc: TRect; vdsk: boolean; pt: TPoint; xbmp: TIEDibBitmap; plc: TWINDOWPLACEMENT; hCursor: THandle; MousePt: TPoint; ClientLeftTop: TPoint; IconInfo: TIconInfo; begin // ASYNC MODE if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateCaptureFromScreen(self, CaptureFromScreen, Source, MouseCursor); exit; end; if not MakeConsistentBitmap([]) then exit; getcursorpos(MousePt); hCursor := Screen.Cursors[-2]; GetIconInfo(hCursor, IconInfo); try ClientLeftTop := Point(0, 0); vdsk := (IEGlobalSettings().OpSys <> ieosWin95) and (IEGlobalSettings().OpSys <> ieosWinNT4); hwin := 0; w := 0; h := 0; x := 0; y := 0; case Source of iecsScreen: begin hwin := GetDesktopWindow; if vdsk then begin x := GetSystemMetrics(76); // SM_XVIRTUALSCREEN y := GetSystemMetrics(77); // SM_YVIRTUALSCREEN w := GetSystemMetrics(78); // SM_CXVIRTUALSCREEN h := GetSystemMetrics(79); // SM_CYVIRTUALSCREEN end else begin // OLDER VERSIONS OF WINDOWS w := Screen.Width; h := Screen.Height; end; dec(MousePt.x, integer(IconInfo.xHotspot)); dec(MousePt.y, integer(IconInfo.yHotspot)); Windows.ScreenToClient(hwin, MousePt); end; iecsPrimary: begin hwin := GetDesktopWindow; if vdsk then begin x := 0; y := 0; w := GetSystemMetrics(0); // SM_CXSCREEN h := GetSystemMetrics(1); // SM_CYSCREEN end else begin // OLDER VERSIONS OF WINDOWS w := Screen.Width; h := Screen.Height; end; dec(MousePt.x, integer(IconInfo.xHotspot)); dec(MousePt.y, integer(IconInfo.yHotspot)); Windows.ScreenToClient(hwin, MousePt); end; iecsForegroundWindow: begin hwin := GetForegroundWindow; if hwin <> 0 then begin plc.length := sizeof(TWINDOWPLACEMENT); GetWindowPlacement(hwin, @plc); if GetWindowRect(hwin, rc) then begin if plc.showCmd = SW_SHOWMAXIMIZED then begin if rc.left < 0 then x := -rc.left; if rc.top < 0 then y := -rc.top; w := rc.Right - x; h := rc.Bottom - y; if rc.left < 0 then rc.left := 0; if rc.top < 0 then rc.top := 0; end else begin w := rc.Right - rc.Left; h := rc.Bottom - rc.Top; end; Windows.ClientToScreen(hwin, ClientLeftTop); dec(MousePt.x, -(ClientLeftTop.x - rc.left) + integer(IconInfo.xHotspot)); dec(MousePt.y, -(ClientLeftTop.y - rc.top) + integer(IconInfo.yHotspot)); Windows.ScreenToClient(hwin, MousePt); end else hwin := 0; end; end; iecsForegroundWindowClient: begin hwin := GetForegroundWindow; if hwin <> 0 then begin if GetClientRect(hwin, rc) then begin pt.x := rc.Left; pt.y := rc.Top; Windows.ClientToScreen(hwin, pt); x := pt.x; y := pt.y; pt.x := rc.Right; pt.y := rc.Bottom; Windows.ClientToScreen(hwin, pt); w := pt.x - x; h := pt.y - y; hwin := GetDesktopWindow; dec(MousePt.x, integer(IconInfo.xHotspot) + x); dec(MousePt.y, integer(IconInfo.yHotspot) + y); end else hwin := 0; end; end; end; if hwin <> 0 then begin xbmp := TIEDibBitmap.Create; xbmp.AllocateBits(w, h, 24); hdc := GetWindowDC(hwin); if hdc <> 0 then begin BitBlt(xbmp.HDC, 0, 0, w, h, hdc, x, y, SRCCOPY); if MouseCursor <> -1 then DrawIconEx(xbmp.HDC, MousePt.x, MousePt.y, hCursor, 0, 0, 0, 0, DI_DEFAULTSIZE or DI_NORMAL); fIEBitmap.Allocate(w, h, ie24RGB); for y := 0 to h - 1 do CopyMemory(fIEBitmap.Scanline[y], xbmp.Scanline[y], fIEBitmap.RowLen); FreeAndNil(xbmp); ReleaseDC(hwin, hdc); Params.DpiX := IEGlobalSettings().SystemDPIX; Params.DpiY := IEGlobalSettings().SystemDPIY; Update(); end; end; finally DeleteObject( IconInfo.hbmMask ); DeleteObject( IconInfo.hbmColor ); end; DoFinishWork; end; {$IFDEF IEINCLUDEPRINTDIALOGS} constructor TIOPrintPreviewParams.Create; begin inherited Create; fMarginTop := 1; fMarginLeft := 1; fMarginRight := 1; fMarginBottom := 1; fPosition := ppCenter; fSize := psFitToPage; fWidth := -1; // default auto-calculated fHeight := -1; // default auto-calculated fGamma := 1; fPrintThumbnails := False; fPrintSelected := False; fThumbnailColumns := 4; fThumbnailRows := 5; fThumbnailSpacing := 0.1; fThumbnailStyle := ptSoftShadow; fThumbnailShowText := True; fDlgWidth := 0; fDlgHeight := 0; end; {!! TIOPrintPreviewParams.SaveToFile Declaration procedure SaveToFile(const FileName: WideString); Description Save all settings of the Print Preview dialog to file. Example // Show Print dialog (remembering the user's settings) if FileExists( PrinterSettingsFilename ) then ImageEnView1.IO.PrintPreviewParams.LoadFromFile( PrinterSettingsFilename ); ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog ); ImageEnView1.IO.PrintPreviewParams.SaveToFile( PrinterSettingsFilename ); !!} procedure TIOPrintPreviewParams.SaveToFile(const FileName: WideString); var fs: TIEWideFileStream; begin fs := TIEWideFileStream.Create(FileName, fmCreate); SaveToStream(fs); FreeAndNil(fs); end; {!! TIOPrintPreviewParams.LoadFromFile Declaration procedure LoadFromFile(const FileName: WideString); Description Load all settings of the Print Preview dialog from file. Example // Show Print dialog (remembering the user's settings) if FileExists( PrinterSettingsFilename ) then ImageEnView1.IO.PrintPreviewParams.LoadFromFile( PrinterSettingsFilename ); ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog ); ImageEnView1.IO.PrintPreviewParams.SaveToFile( PrinterSettingsFilename ); !!} procedure TIOPrintPreviewParams.LoadFromFile(const FileName: WideString); var fs: TIEWideFileStream; begin fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try LoadFromStream(fs); finally FreeAndNil(fs); end; end; {!! TIOPrintPreviewParams.SaveToStream Declaration procedure SaveToStream(Stream: TStream); Description Save all settings of the Print Preview dialog to a stream. Example // Show Print dialog (remembering the user's settings) if FileExists( PrinterSettingsStream ) then ImageEnView1.IO.PrintPreviewParams.LoadFromStream( PrinterSettingsStream ); ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog ); ImageEnView1.IO.PrintPreviewParams.SaveToStream( PrinterSettingsStream ); !!} procedure TIOPrintPreviewParams.SaveToStream(Stream: TStream); begin Stream.Write(fMarginTop, sizeof(double)); Stream.Write(fMarginLeft, sizeof(double)); Stream.Write(fMarginRight, sizeof(double)); Stream.Write(fMarginBottom, sizeof(double)); Stream.Write(fPosition, sizeof(TIOPrintPreviewPosition)); Stream.Write(fSize, sizeof(TIOPrintPreviewSize)); Stream.Write(fWidth, sizeof(double)); Stream.Write(fHeight, sizeof(double)); Stream.Write(fGamma, sizeof(double)); Stream.Write(fPrintThumbnails, sizeof(Boolean)); Stream.Write(fThumbnailColumns, sizeof(Integer)); Stream.Write(fThumbnailRows, sizeof(Integer)); Stream.Write(fThumbnailSpacing, sizeof(double)); Stream.Write(fThumbnailStyle, sizeof(TIOPrintPreviewThumbnailStyle)); Stream.Write(fThumbnailShowText, sizeof(Boolean)); Stream.Write(fDlgWidth, sizeof(Integer)); Stream.Write(fDlgHeight, sizeof(Integer)); Stream.Write(fPrintSelected, sizeof(Boolean)); end; {!! TIOPrintPreviewParams.LoadFromStream Declaration procedure LoadFromStream(Stream: TStream); Description Loads all settings of the Print Preview dialog from a stream. Example // Show Print dialog (remembering the user's settings) if FileExists( PrinterSettingsStream ) then ImageEnView1.IO.PrintPreviewParams.LoadFromStream( PrinterSettingsStream ); ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog ); ImageEnView1.IO.PrintPreviewParams.SaveToStream( PrinterSettingsStream ); !!} procedure TIOPrintPreviewParams.LoadFromStream(Stream: TStream); begin Stream.Read(fMarginTop, sizeof(double)); Stream.Read(fMarginLeft, sizeof(double)); Stream.Read(fMarginRight, sizeof(double)); Stream.Read(fMarginBottom, sizeof(double)); Stream.Read(fPosition, sizeof(TIOPrintPreviewPosition)); Stream.Read(fSize, sizeof(TIOPrintPreviewSize)); Stream.Read(fWidth, sizeof(double)); Stream.Read(fHeight, sizeof(double)); Stream.Read(fGamma, sizeof(double)); Stream.Read(fPrintThumbnails, sizeof(Boolean)); Stream.Read(fThumbnailColumns, sizeof(Integer)); Stream.Read(fThumbnailRows, sizeof(Integer)); Stream.Read(fThumbnailSpacing, sizeof(double)); Stream.Read(fThumbnailStyle, sizeof(TIOPrintPreviewThumbnailStyle)); Stream.Read(fThumbnailShowText, sizeof(Boolean)); Stream.Read(fDlgWidth, sizeof(Integer)); Stream.Read(fDlgHeight, sizeof(Integer)); Stream.Read(fPrintSelected, sizeof(Boolean)); end; {!! TIOPrintPreviewParams.GetProperty Declaration function GetProperty(const Prop: WideString): WideString; Description Read a property of the Print Preview dialog using its string representation. !!} function TIOPrintPreviewParams.GetProperty(const Prop: WideString): WideString; var ss: WideString; begin ss := UpperCase(IERemoveCtrlCharsW(Prop)); if ss = PPP_MARGINTOP then result := IEFloatToStrW(fMarginTop) else if ss = PPP_MARGINLEFT then result := IEFloatToStrW(fMarginLeft) else if ss = PPP_MARGINRIGHT then result := IEFloatToStrW(fMarginRight) else if ss = PPP_MARGINBOTTOM then result := IEFloatToStrW(fMarginBottom) else if ss = PPP_POSITION then result := IntToStr(integer(fPosition)) else if ss = PPP_SIZE then result := IntToStr(integer(fSize)) else if ss = PPP_WIDTH then result := IEFloatToStrW(fWidth) else if ss = PPP_HEIGHT then result := IEFloatToStrW(fHeight) else if ss = PPP_GAMMA then result := IEFloatToStrW(fGamma) else if ss = PPP_PRINTTHUMBNAILS then Result := IEBool2StrW(fPrintThumbnails) else if ss = PPP_THUMBNAILCOLUMNS then Result := IntToStr(fThumbnailColumns) else if ss = PPP_THUMBNAILROWS then Result := IntToStr(fThumbnailRows) else if ss = PPP_THUMBNAILSPACING then Result := IEFloatToStrW(fThumbnailSpacing) else if ss = PPP_THUMBNAILSTYLE then Result := IntToStr(Integer(fThumbnailStyle)) else if ss = PPP_THUMBNAILSHOWTEXT then Result := IEBool2StrW(fThumbnailShowText) else if ss = PPP_DLGWIDTH then Result := IntToStr(fDlgWidth) else if ss = PPP_DLGHEIGHT then Result := IntToStr(fDlgHeight) else if ss = PPP_PRINTSELECTED then Result := IEBool2StrW(fPrintSelected); end; {!! TIOPrintPreviewParams.SetProperty Declaration procedure SetProperty(Prop, Value: WideString); Description Write a property of the Print Preview dialog using its string representation. !!} procedure TIOPrintPreviewParams.SetProperty(Prop, Value: WideString); var ss: WideString; begin ss := UpperCase(IERemoveCtrlCharsW(Prop)); Value := IERemoveCtrlCharsW(Value); if ss = PPP_MARGINLEFT then fMarginLeft := IEStrToFloatDefW(value, 0) else if ss = PPP_MARGINRIGHT then fMarginRight := IEStrToFloatDefW(value, 0) else if ss = PPP_MARGINTOP then fMarginTop := IEStrToFloatDefW(value, 0) else if ss = PPP_MARGINBOTTOM then fMarginBottom := IEStrToFloatDefW(value, 0) else if ss = PPP_POSITION then fPosition := TIOPrintPreviewPosition(StrToIntDef(value, 0)) else if ss = PPP_SIZE then fSize := TIOPrintPreviewSize(StrToIntDef(value, 0)) else if ss = PPP_WIDTH then fWidth := IEStrToFloatDefW(value, 0) else if ss = PPP_HEIGHT then fHeight := IEStrToFloatDefW(value, 0) else if ss = PPP_GAMMA then fGamma := IEStrToFloatDefW(value, 0) else if ss = PPP_PRINTTHUMBNAILS then fPrintThumbnails := IEStr2BoolW(value) else if ss = PPP_THUMBNAILCOLUMNS then fThumbnailColumns := StrToIntDef(value, 4) else if ss = PPP_THUMBNAILROWS then fThumbnailRows := StrToIntDef(value, 5) else if ss = PPP_THUMBNAILSPACING then fThumbnailSpacing := IEStrToFloatDefW(value, 0) else if ss = PPP_THUMBNAILSTYLE then fThumbnailStyle := TIOPrintPreviewThumbnailStyle(StrToIntDef(value, 0)) else if ss = PPP_THUMBNAILSHOWTEXT then fThumbnailShowText := IEStr2BoolW(value) else if ss = PPP_DLGWIDTH then fDlgWidth := StrToIntDef(value, 0) else if ss = PPP_DLGHEIGHT then fDlgHeight := StrToIntDef(value, 0) else if ss = PPP_PRINTSELECTED then fPrintSelected := IEStr2BoolW(value); end; {!! TImageEnIO.DoPrintPreviewDialog Declaration function DoPrintPreviewDialog(DialogType: = iedtDialog; const TaskName: WideString = ''; PrintAnnotations: Boolean = false; const Caption: WideString = ''; PrintLayers: Boolean = false): Boolean; Description Displays a print preview dialog to allow the user to configure and print the current image. Parameter Description FC>DialogType Select the style of print dialog FC>TaskName Specifes the text that describes the task in the Print Manager and network header pages FC>PrintAnnotations If true and the image contains imaging or ImageEn annotations they will be printed FC>Caption Specifies the caption of the Print Preview dialog FC>PrintLayers If true and the attached image contains multiple layers, they will be printed. If False, only the image (i.e. current layer) is printed
Note: The language used in the dialog is controlled by . The styling can also be adjusted using Demos Demos\FullApps\PhotoEn3\ImageEx.dpr Demos\InputOutput\PrintSelected\PrintSelected.dpr Example ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog ); ImageEnView1.IO.DoPrintPreviewDialog( iedtMaxi ); // Preview image with layers ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog, '', False, '', True ); // If an area of the image is selected, print the selection, otherwise print the whole image procedure TForm1.PrintImageClick(Sender: TObject); var bmp: TIEBitmap; IO: TImageEnIO; begin if ImageEnView1.Selected = False then ImageEnView1.IO.DoPrintPreviewDialog( iedtDialog, '' ) else begin bmp := TIEBitmap.Create; IO := TImageEnIO.CreateFromBitmap( bmp ); try ImageEnView1.CopySelectionToBitmap( bmp ); IO.DoPrintPreviewDialog( iedtDialog, '' ); finally IO.Free; bmp.Free; end; end; end; See Also - - !!} function TImageEnIO.DoPrintPreviewDialog(DialogType: TIEDialogType; const TaskName: WideString; PrintAnnotations: Boolean; const Caption: WideString; PrintLayers: Boolean): boolean; var fieprnform1: tfieprnform1; fieprnform2: tfieprnform2; begin if fResetPrinter then try IEResetPrinter(); except MessageDlg('The Print Preview could not be displayed because a printer has not been configured on this computer.', mtError, [mbOK], 0); result := false; exit; end; result := false; if not MakeConsistentBitmap([]) then exit; GeneratePrintBitmap( PrintAnnotations, PrintLayers ); if (fPrintBitmap.Width <= 1) and (fPrintBitmap.Height <= 1) then begin FreeAndNil( fPrintBitmap ); exit; end; case DialogType of iedtDialog: begin fieprnform2 := tfieprnform2.Create(self); try fieprnform2.io := self; fieprnform2.fDialogsMeasureUnit := fDialogsMeasureUnit; fieprnform2.UpdateLanguage(); if fPreviewFontEnabled then fieprnform2.Font.Assign(fPreviewFont) else fieprnform2.Font.Assign(IEGetDefaultDialogFont); fieprnform2.fTaskName := TaskName; fieprnform2.fPrintPreviewParams := fPrintPreviewParams; fieprnform2.PrintAnnotations := PrintAnnotations; if Caption <> '' then fieprnform2.Caption := Caption else fieprnform2.Caption := iemsg(IEMSG_PRINT); if assigned(fOnIOPreview) then fOnIOPreview(self, fieprnform2); result := fieprnform2.ShowModal = mrOk; finally fieprnform2.Release; end; end; iedtMaxi: begin fieprnform1 := tfieprnform1.Create(self); try fieprnform1.io := self; fieprnform1.fDialogsMeasureUnit := fDialogsMeasureUnit; fieprnform1.UpdateLanguage(); if fPreviewFontEnabled then fieprnform1.Font.Assign(fPreviewFont) else fieprnform1.Font.Assign(IEGetDefaultDialogFont); fieprnform1.fTaskName := TaskName; fieprnform1.Left := 0; fieprnform1.Top := 0; fieprnform1.fPrintPreviewParams := fPrintPreviewParams; fieprnform1.PrintAnnotations := PrintAnnotations; if Caption <> '' then fieprnform1.Caption := Caption else fieprnform1.Caption := iemsg(IEMSG_PRINT); if assigned(fOnIOPreview) then fOnIOPreview(self, fieprnform1); result := fieprnform1.ShowModal = mrOk; finally fieprnform1.Release; end; end; end; FreeAndNil( fPrintBitmap ); end; {$ENDIF} procedure TImageEnIO.AdjustDPI; var new_w, new_h: integer; newbmp, oldalpha: TIEBitmap; begin if not MakeConsistentBitmap([]) then exit; if (fParams.DpiX <> fParams.DpiY) and (fParams.DpiX > 0) and (fParams.DpiY > 0) and (fIEBitmap.Width > 0) and (fIEBitmap.Height > 0) and (fParams.Height > 0) and (fParams.Width > 0) then begin newbmp := TIEBitmap.Create; if fParams.Width > fParams.Height then begin new_h := trunc((fParams.Height / fParams.fDpiY) * fParams.fDpiX); new_w := fParams.Width; fParams.fDpiY := fParams.fDpiX; fParams.Height := new_h; end else begin new_w := trunc((fParams.Width / fParams.fDpiX) * fParams.fDpiY); new_h := fParams.Height; fParams.fDpiX := fParams.fDpiY; fParams.Width := new_w; end; if fIEBitmap.HasAlphaChannel then begin oldalpha := TIEBitmap.Create; oldalpha.assign(fIEBitmap.AlphaChannel); end else oldalpha := nil; if fFilteredAdjustDPI then begin newbmp.Allocate(new_w, new_h, ie24RGB); if fIEBitmap.PixelFormat <> ie24RGB then fIEBitmap.PixelFormat := ie24RGB; _ResampleEx(fIEBitmap, newbmp, nil, IEGlobalSettings().DefaultResampleFilter, nil, nil); end else begin newbmp.Allocate(new_w, new_h, fIEBitmap.PixelFormat); _IEBmpStretchEx(fIEBitmap, newbmp, nil, nil); end; fIEBitmap.Assign(newbmp); FreeAndNil(newbmp); // stretch alpha if assigned(oldalpha) then begin _IEBmpStretchEx(oldalpha, fIEBitmap.AlphaChannel, nil, nil); FreeAndNil(oldalpha); end; end; end; // return frame count {!! TImageEnIO.OpenAVIFile Declaration function OpenAVIFile(const FileName: WideString): Integer; Description Opens an AVI file without reading any frames. The result is the number of frames contained in the AVI. Example // Save the first AVI frame to 'frame1.jpg', second frame to 'frame2.jpg' ImageEnView1.IO.OpenAVIFile( 'C:\film.avi' ); ImageEnView1.IO.LoadFromAVI( 0 ); ImageEnView1.IO.SaveToFile('D:\frame1.jpg'); ImageEnView1.IO.LoadFromAVI( 1 ); ImageEnView1.IO.SaveToFile('D:\frame2.jpg'); ... ImageEnView1.IO.CloseAVIFile; See Also - - - !!} function TImageEnIO.OpenAVIFile(const FileName: WideString): integer; var psi: TAviStreamInfoW; begin fAborting := false; if fAVI_avf <> nil then CloseAVIFile(); result := 0; fParams.AVI_FrameCount := 0; try fParams.FileName := FileName; fParams.FileType := ioUnknown; if not gAVIFILEinit then begin AVIFileInit(); gAVIFILEinit := true; end; if AVIFileOpenW(PAVIFILE(fAVI_avf), PWideChar(FileName), OF_READ, nil) <> 0 then begin fAborting := True; exit; end; if AVIFileGetStream(PAVIFILE(fAVI_avf), PAVISTREAM(fAVI_avs), streamtypeVIDEO, 0) <> 0 then begin AVIFileRelease(fAVI_avf); fAborting := True; exit; end; if AVIStreamInfoW(PAVISTREAM(fAVI_avs), psi, sizeof(TAVISTREAMINFOW)) <> 0 then begin AVIFileRelease(fAVI_avf); AVIStreamRelease(fAVI_avs); fAborting := True; exit; end; move(psi, fAVI_psi, sizeof(TAviStreamInfoW_Ex)); fAVI_gf := AVIStreamGetFrameOpen(fAVI_avs, nil); if fAVI_gf = nil then begin AVIFileRelease(fAVI_avf); AVIStreamRelease(fAVI_avs); fAborting := True; exit; end; result := fAVI_psi.dwLength; fParams.AVI_FrameCount := fAVI_psi.dwLength; fParams.AVI_FrameDelayTime := 1000 / (fAVI_psi.dwRate/fAVI_psi.dwScale); finally if fAborting then begin fAVI_avf := nil; fAVI_avs := nil; fAVI_gf := nil; end; end; end; {!! TImageEnIO.CloseAVIFile Declaration procedure CloseAVIFile; Description Closes an AVI file that was opened with or . Demo Demos\VideoCapture\DesktopToAvi\DesktopToAvi.dpr Example // Save the first AVI frame to 'frame1.jpg', second frame to 'frame2.jpg' ImageEnView1.IO.OpenAVIFile( 'C:\film.avi' ); ImageEnView1.IO.LoadFromAVI( 0 ); ImageEnView1.IO.SaveToFile('D:\frame1.jpg'); ImageEnView1.IO.LoadFromAVI( 1 ); ImageEnView1.IO.SaveToFile('D:\frame2.jpg'); ... ImageEnView1.IO.CloseAVIFile; !!} procedure TImageEnIO.CloseAVIFile; begin if fAVI_avs1 <> nil then begin // save AVISaveOptionsFree(1, PAVICOMPRESSOPTIONS(fAVI_popts)); freemem(fAVI_popts); if fAVI_avs <> nil then AVIStreamRelease(fAVI_avs); AVIStreamRelease(fAVI_avs1); AVIFileRelease(fAVI_avf); fAVI_popts := nil; fAVI_avs := nil; fAVI_avs1 := nil; fAVI_avf := nil; end else begin // load if fAVI_avf = nil then exit; AVIStreamGetFrameClose(fAVI_gf); AVIStreamRelease(fAVI_avs); AVIFileRelease(fAVI_avf); fAVI_avf := nil; fAVI_avs := nil; fAVI_gf := nil; end; end; {!! TImageEnIO.IsOpenAVI Declaration function IsOpenAVI: Boolean; Description Returns True when has a currently open file. !!} function TImageEnIO.IsOpenAVI: Boolean; begin result := (fAVI_avf <> nil) and (fAVI_avs <> nil) and (fAVI_gf <> nil); end; {!! TImageEnIO.LoadFromAVI Declaration function LoadFromAVI(FrameIndex: Integer): Boolean; Description Reads the frame of index, FrameIndex, opened with . Result will be false if the file is not a recognized file type (and will be false). Loading errors due to a file not being available will raise an exception. Example // Save first AVI frame to 'frame1.jpg', second frame to 'frame2.jpg' ImageEnView1.IO.OpenAVIFile( 'C:\film.avi' ); ImageEnView1.IO.LoadFromAVI( 0 ); ImageEnView1.IO.SaveToFile('D:\frame1.jpg'); ImageEnView1.IO.LoadFromAVI( 1 ); ImageEnView1.IO.SaveToFile('D:\frame2.jpg'); ... ImageEnView1.IO.CloseAVIFile; !!} function TImageEnIO.LoadFromAVI(FrameIndex: integer): Boolean; var pt: pointer; bitcount: integer; dib: TIEDibBitmap; iBitsPerSample, iSamplesPerPixel: Integer; begin CheckHaveValidBitmap(); Result := False; // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveIndexRetBool(self, LoadFromAVI, FrameIndex); exit; end; try fAborting := false; if not MakeConsistentBitmap([]) then exit; if (fAVI_avf = nil) or (fAVI_avs = nil) or (fAVI_gf = nil) then exit; if dword(FrameIndex) >= fAVI_psi.dwLength then exit; pt := AVIStreamGetFrame(fAVI_gf, FrameIndex); fParams.AVI_FrameCount := fAVI_psi.dwLength; fParams.AVI_FrameDelayTime := 1000 / (fAVI_psi.dwRate/fAVI_psi.dwScale); dib := TIEDibBitmap.create; if pt <> nil then begin bitcount := _IECopyDIB2Bitmap2Ex(uint64(pt), dib, nil, true); // uses drawdibdraw fIEBitmap.CopyFromTDibBitmap(dib); BitCountToBPSAndSPP( BitCount, False, iBitsPerSample, iSamplesPerPixel ); fParams.BitsPerSample := iBitsPerSample; fParams.SamplesPerPixel := iSamplesPerPixel; fParams.DpiX := IEGlobalSettings().DefaultDPIX; fParams.DpiY := IEGlobalSettings().DefaultDPIY; fParams.Width := dib.Width; fParams.Height := dib.Height; fParams.OriginalWidth := dib.Width; fParams.OriginalHeight := dib.Height; fParams.FreeColorMap; Update(); Result := Not fAborting; ResetModified(); end; FreeAndNil(dib); finally DoFinishWork; end; end; {!! TImageEnIO.CreateAVIFile Declaration function CreateAVIFile(const FileName: WideString; rate: Integer; const codec: AnsiString): TIECreateAVIFileResult; Description Creates a new, empty AVI file. FileName: Full destination path Rate: Specifies the number of frames per second Code: The compression codec to use (must be installed on system) as a four characters string. For example: 'cvid' : cinepak by Radius 'msvc' : Microsoft Video 1 'mp42' : Microsoft MPEG4 V2 More codecs are listed at www.fourcc.org or by searching for registered fourcc codes and wave formats on MSDN You can save each frame to the created AVI file using the method. Finally, call to close the file. Example ImageEnView.IO.CreateAVIFile('D:\output.avi', 20, 'DIB '); // save frame 0 ImageEnView.IO.LoadFromFile('C:\frame0.jpg'); ImageEnView.IO.Params.BitsPerSample := 8; ImageEnView.IO.Params.SamplesPerPixel := 1; ImageEnView.IO.SaveToAVI; // save frame 1 ImageEnView.IO.LoadFromFile('C:\frame1.jpg'); ImageEnView.IO.Params.BitsPerSample := 8; ImageEnView.IO.Params.SamplesPerPixel := 1; ImageEnView.IO.SaveToAVI; // close the file ImageEnView.IO.CloseAVIFile; !!} function TImageEnIO.CreateAVIFile(const FileName: WideString; rate: Double; const codec: AnsiString): TIECreateAVIFileResult; var psi: TAviStreamInfoW; hr: HResult; num, den: integer; begin fAborting := False; if not gAVIFILEinit then begin AVIFileInit; gAVIFILEinit := true; end; if IEFileExistsW(FileName) then DeleteFileW(PWideChar(FileName)); if AVIFileOpenW(PAVIFILE(fAVI_avf), PWideChar(FileName), OF_WRITE or OF_CREATE, nil) <> 0 then raise EInvalidGraphic.Create('unable to create AVI file'); ZeroMemory(@psi, sizeof(psi)); psi.fccType := streamtypeVIDEO; IEDecimalToFraction(rate, num, den); psi.dwScale := den; psi.dwRate := num; psi.dwQuality := $FFFFFFFF; fAVI_popts := allocmem(sizeof(TAVICOMPRESSOPTIONS)); if (fParams.BitsPerSample = 8) and (fParams.SamplesPerPixel = 1) then psi.dwSuggestedBufferSize := IEBitmapRowLen(fParams.Width, 8, 32) * fParams.Height else psi.dwSuggestedBufferSize := IEBitmapRowLen(fParams.Width, 24, 32) * fParams.Height; psi.rcFrame := rect(0, 0, fParams.Width, fParams.Height); AVIFileCreateStreamW(PAVIFILE(fAVI_avf), PAVISTREAM(fAVI_avs1), psi); if codec = '' then begin if not AVISaveOptions(0, 0, 1, @fAVI_avs1, @fAVI_popts) then begin AVIStreamRelease(fAVI_avs1); fAVI_avs1 := nil; AVIFileRelease(fAVI_avf); fAVI_avf := nil; freemem(fAVI_popts); fAborting := True; result := ieaviNOCOMPRESSOR; exit; // EXIT POINT end; end else begin PAVICOMPRESSOPTIONS(fAVI_popts)^.fccType := streamtypeVIDEO; PAVICOMPRESSOPTIONS(fAVI_popts)^.fccHandler := pinteger(PAnsiChar(codec))^; PAVICOMPRESSOPTIONS(fAVI_popts)^.dwKeyFrameEvery := 0; PAVICOMPRESSOPTIONS(fAVI_popts)^.dwQuality := $FFFFFFFF; PAVICOMPRESSOPTIONS(fAVI_popts)^.dwBytesPerSecond := 0; PAVICOMPRESSOPTIONS(fAVI_popts)^.dwFlags := 0; PAVICOMPRESSOPTIONS(fAVI_popts)^.lpFormat := nil; PAVICOMPRESSOPTIONS(fAVI_popts)^.cbFormat := 0; PAVICOMPRESSOPTIONS(fAVI_popts)^.lpParms := nil; PAVICOMPRESSOPTIONS(fAVI_popts)^.cbParms := 0; PAVICOMPRESSOPTIONS(fAVI_popts)^.dwInterleaveEvery := 0; end; hr := AVIMakeCompressedStream(PAVISTREAM(fAVI_avs), PAVISTREAM(fAVI_avs1), fAVI_popts, nil); if hr = AVIERR_NOCOMPRESSOR then result := ieaviNOCOMPRESSOR else if hr = AVIERR_MEMORY then result := ieaviMEMORY else if hr = AVIERR_UNSUPPORTED then result := ieaviUNSUPPORTED else result := ieaviOK; fAborting := result <> ieaviOK; fAVI_idx := 0; end; {!! TImageEnIO.SaveToAVI Declaration procedure SaveToAVI; Description Saves the current image to an AVI file opened using . It is recommended that you set . and . before calling , because AVI requires all images to have the same color depth. Demo Demos\VideoCapture\DesktopToAvi\DesktopToAvi.dpr Example ImageEnView.IO.CreateAVIFile('output.avi', 20, 'DIB '); // save frame 0 ImageEnView.IO.LoadFromFile('C:\frame0.jpg'); ImageEnView.IO.Params.BitsPerSample := 8; ImageEnView.IO.Params.SamplesPerPixel := 1; ImageEnView.IO.SaveToAVI(); // save frame 1 ImageEnView.IO.LoadFromFile('C:\frame1.jpg'); ImageEnView.IO.Params.BitsPerSample := 8; ImageEnView.IO.Params.SamplesPerPixel := 1; ImageEnView.IO.SaveToAVI(); // close the file ImageEnView.IO.CloseAVIFile(); !!} procedure TImageEnIO.SaveToAVI; type TBitmapInfoHeader256Ex = packed record biSize: DWORD; biWidth: Longint; biHeight: Longint; biPlanes: Word; biBitCount: Word; biCompression: DWORD; biSizeImage: DWORD; biXPelsPerMeter: Longint; biYPelsPerMeter: Longint; biClrUsed: DWORD; biClrImportant: DWORD; Palette: array[0..255] of TRGBQUAD; end; PBitmapInfoHeader256Ex = ^TBitmapInfoHeader256Ex; var he: TBitmapInfoHeader256Ex; i: integer; sw, sx: integer; bmp: TIEBitmap; begin CheckHaveValidBitmap(); if (fAVI_avs = nil) or (not MakeConsistentBitmap([])) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; bmp := TIEBitmap.Create(); try bmp.Location := ieMemory; bmp.Assign(fIEBitmap); // set video format he.biSize := sizeof(TBitmapInfoHeader); he.biWidth := bmp.Width; he.biHeight := bmp.Height; he.biPlanes := 1; he.biCompression := BI_RGB; he.biXPelsPerMeter := 0; he.biYPelsPerMeter := 0; he.biClrImportant := 0; if (fParams.SamplesPerPixel = 1) and (fParams.BitsPerSample = 8) then begin // 256 colors he.biClrUsed := 256; bmp.PixelFormat := ie8p; he.biSizeImage := bmp.RowLen * bmp.Height; he.biBitCount := 8; for i := 0 to 255 do begin he.Palette[i].rgbRed := bmp.Palette[i].r; he.Palette[i].rgbGreen := bmp.Palette[i].g; he.Palette[i].rgbBlue := bmp.Palette[i].b; he.Palette[i].rgbReserved := 0; end; AVIStreamSetFormat(fAVI_avs, fAVI_idx, @he, sizeof(TBITMAPINFOHEADER) + 256 * sizeof(TRGBQUAD)); end else if bmp.HasAlphaChannel then begin // 32bit RGBA bmp.PixelFormat := ie32RGB; bmp.SynchronizeRGBA(false); // alpha to RGBA he.biClrUsed := 0; he.biBitCount := 32; //he.biCompression := IEBI_RGBA; // <- don't work with it! he.biSizeImage := bmp.RowLen * bmp.Height; if fAVI_idx = 0 then AVIStreamSetFormat(fAVI_avs, 0, @he, sizeof(TBITMAPINFOHEADER)); end else begin // 24 bit he.biClrUsed := 0; he.biBitCount := 24; he.biSizeImage := bmp.RowLen * bmp.Height; if fAVI_idx = 0 then AVIStreamSetFormat(fAVI_avs, 0, @he, sizeof(TBITMAPINFOHEADER)); end; sw := 0; sx := 0; AVIStreamWrite(fAVI_avs, fAVI_idx, 1, bmp.Scanline[bmp.Height - 1], he.biSizeImage, AVIIF_KEYFRAME, @sx, @sw); finally FreeAndNil(bmp); end; inc(fAVI_idx); end; {!! TImageEnIO.MergeMetaFile Declaration procedure MergeMetafile(const FileName: WideString; x, y, Width, Height: Integer); Description Loads a metafile and draws it at the x, y position using sizes of Width and Height. If Width or Height is -1 the other is auto-calculated to maintain the aspect ratio. Example ImageEnView1.io.LoadFromFile('C:\backgroundimage.jpg'); ImageEnView1.io.MergeMetaFile('C:\overimage.wmf', 100, 100, 120, -1); !!} // If Width or Height is -1 then it is auto-calculated maintain aspect ratio // Import... because this is a vectorial image // Doesn't set IO params // DON't USE INSIDE A THREAD procedure TImageEnIO.MergeMetafile(const FileName: WideString; x, y, Width, Height: integer); const MAXDIMS = 16000; var meta: TMetafile; dib: TIEDibBitmap; dibcanvas: TCanvas; begin try fAborting := false; if (Width = 0) or (Height = 0) then exit; if not MakeConsistentBitmap([]) then exit; meta := tmetafile.create; try meta.LoadFromFile(FileName); if (Width >= 0) or (Height >= 0) then begin if (Width >= 0) and (Height >= 0) then begin meta.Width := Width; meta.Height := Height; end else begin if Width < 0 then begin meta.Width := (meta.Width * Height) div meta.Height; meta.Height := Height; end else if Height < 0 then begin meta.Height := (meta.Height * Width) div meta.Width; meta.Width := Width; end; end; end; if (meta.width = 0) or (meta.height = 0) then begin fAborting := true; exit; // finally will be executed (meta.free) end; if (meta.width > MAXDIMS) or (meta.height > MAXDIMS) then begin if meta.Height > meta.Width then begin meta.Width := (meta.Width * MAXDIMS) div meta.Height; meta.Height := MAXDIMS; end else begin meta.Height := (meta.Height * MAXDIMS) div meta.Width; meta.Width := MAXDIMS; end; end; meta.transparent := true; dib := TIEDibBitmap.Create; dibcanvas := TCanvas.Create; dib.AllocateBits(meta.Width - 1, meta.Height - 1, 24); fIEBitmap.CopyToTDibBitmap(dib, x, y, dib.Width, dib.Height); dibcanvas.Handle := dib.HDC; dibCanvas.Draw(0, 0, meta); fIEBitmap.MergeFromTDibBitmap(dib, x, y); FreeAndNil(dibcanvas); FreeAndNil(dib); finally FreeAndNil(meta); end; Update(); finally DoFinishWork; end; end; // doesn't set fParams.FileType {$IFDEF IEINCLUDEJPEG2000} function TImageEnIO.LoadFromStreamJ2000(Stream: TStream): Boolean; var Progress: TProgressRec; begin CheckHaveValidBitmap(); Result := False; fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; J2KReadStream(Stream, fIEBitmap, fParams, Progress, False); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; Result := Not fAborting; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.LoadFromStreamJP2 Declaration function LoadFromStreamJP2(Stream: TStream): Boolean; Description Loads an image from a stream containing a Jpeg2000 (JP2) file. The result will be false if an error is encountered, e.g. the file in the stream is not JPEG2000 format ( will be true). !!} function TImageEnIO.LoadFromStreamJP2(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamJP2, Stream); Result := True; exit; end; try Result := LoadFromStreamJ2000(Stream); fParams.FileType := ioJP2; Update(); ResetModified(); finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.LoadFromStreamJ2K Declaration function LoadFromStreamJ2K(Stream: TStream): Boolean; Description Loads an image from a stream containing a Jpeg2000 (J2K code stream) file. The result will be false if an error is encountered, e.g. the file in the stream is not JPEG2000 format ( will be true). !!} function TImageEnIO.LoadFromStreamJ2K(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamJ2K, Stream); Result := True; exit; end; try Result := LoadFromStreamJ2000(Stream); fParams.FileType := ioJ2K; Update(); ResetModified(); finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.LoadFromFileJ2K Declaration function LoadFromFileJ2K(const FileName: WideString): Boolean; Description Loads an image from a Jpeg2000 (J2K code stream) file. FileName is the file name including extension. Result will be false if the file is not a JPEG2000 (and will be false). Loading errors due to a file not being available will raise an exception. !!} function TImageEnIO.LoadFromFileJ2K(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileJ2K, FileName); Result := True; exit; end; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); fAborting := false; try Result := LoadFromStreamJ2000(fs); fParams.FileName := FileName; fParams.FileType := ioJ2K; finally FreeAndNil(fs); end; Update(); ResetModified(); finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.LoadFromFileJP2 Declaration function LoadFromFileJP2(const FileName: WideString): Boolean; Description Loads an image from a Jpeg2000 (JP2) file. FileName is the file name including extension. Result will be false if the file is not JPEG2000 format (and will be false). Loading errors due to a file not being available will raise an exception. !!} function TImageEnIO.LoadFromFileJP2(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileJP2, FileName); Result := True; exit; end; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); fAborting := false; try Result := LoadFromStreamJ2000(fs); fParams.FileName := FileName; fParams.FileType := ioJP2; finally FreeAndNil(fs); end; Update(); ResetModified(); finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} procedure TImageEnIO.SaveToStreamJ2000(Stream: TStream; format: integer); var Progress: TProgressRec; begin CheckHaveValidBitmap(); fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([ie1g, ie8g, ie16g, ie24RGB]) then exit; J2KWriteStream(Stream, fIEBitmap, fParams, Progress, format); end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.SaveToStreamJP2 Declaration procedure SaveToStreamJP2(Stream: TStream); Description Saves the current image to a stream in Jpeg2000 (JP2) format. !!} procedure TImageEnIO.SaveToStreamJP2(Stream: TStream); begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamJP2, Stream); exit; end; try SaveToStreamJ2000(Stream, 0); finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.SaveToStreamJ2K Declaration procedure SaveToStreamJ2K(Stream: TStream); Description Saves the current image to a stream in Jpeg2000 (J2K code stream) format. !!} procedure TImageEnIO.SaveToStreamJ2K(stream: TStream); begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamJ2K, Stream); exit; end; try SaveToStreamJ2000(Stream, 1); finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.SaveToFileJP2 Declaration procedure SaveToFileJP2(const FileName: WideString); Description Saves the current image to a file in Jpeg2000 (JP2) format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. !!} procedure TImageEnIO.SaveToFileJP2(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileJP2, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try SaveToStreamJ2000(fs, 0); fParams.FileName := FileName; fParams.FileType := ioJP2; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {$ENDIF} {$IFDEF IEINCLUDEJPEG2000} {!! TImageEnIO.SaveToFileJ2K Declaration procedure SaveToFileJ2K(const FileName: WideString); Description Saves the current image to a file in Jpeg2000 (J2K code stream) format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. !!} procedure TImageEnIO.SaveToFileJ2K(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileJ2K, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try SaveToStreamJ2000(fs, 1); fParams.FileName := FileName; fParams.FileType := ioJ2K; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {$ENDIF} {!! TImageEnIO.IEBitmap Declaration property IEBitmap: Description Contains the attached object (same value as the property). !!} procedure TImageEnIO.SetIEBitmap(bmp: TIEBitmap); begin fBitmap := nil; if fIEBitmapCreated then FreeAndNil(fIEBitmap); fIEBitmapCreated := false; fIEBitmap := bmp; end; {!! TImageEnIO.AttachedIEBitmap Declaration property AttachedIEBitmap: Description Contains the attached object (same value as the property). Example // multithread saving Var Bmp: TIEBitmap; Io: TImageEnIO; Begin Bmp := TIEBitmap.Create; Io := TImageEnIO.CreateFromBitmap(bmp); Io.LoadFromFile('C:\input.bmp'); Io.AsyncMode := True; // this makes a thread foreach input/output task Io.SaveToFile('D:\i1.jpg'); // thread 1 Io.SaveToFile('D:\i2.jpg'); // thread 2 Io.SaveToFile('D:\i3.jpg'); // thread 3 Io.Free; // free method waits for all tasks end! Bmp.Free; End; !!} procedure TImageEnIO.SetAttachedIEBitmap(bmp: TIEBitmap); begin if assigned(fImageEnView) then fImageEnView.RemoveBitmapChangeEvent(fImageEnViewBitmapChangeHandle); // remove previous if exists if (not assigned(bmp)) and (assigned(fImageEnView) or assigned(fTImage)) then exit; // error SetIEBitmap(bmp); if assigned(bmp) then begin fImageEnView := nil; fTImage := nil; end; end; procedure TImageEnIO.SetBitmap(bmp: TBitmap); begin fBitmap := bmp; fIEBitmap.EncapsulateTBitmap(fBitmap, true); end; {!! TImageEnIO.AttachedBitmap Declaration property AttachedBitmap: TBitmap; Description Use this property to attach a TImageEnIO to a normal TBitmap object to provide wider format support and functionality. This property is mutually exclusive with and . Example var bmp: TBitmap; Begin bmp := TBitmap.Create; ImageEnIO1.AttachedBitmap := bmp; ImageEnIO1.LoadFromFile('C:\alfa.tif'); ... End; !!} procedure TImageEnIO.SetAttachedBitmap(atBitmap: TBitmap); begin if assigned(fImageEnView) then fImageEnView.RemoveBitmapChangeEvent(fImageEnViewBitmapChangeHandle); // remove previous if exists if (not assigned(atBitmap)) and (assigned(fImageEnView) or assigned(fTImage)) then exit; // error fBitmap := atBitmap; if assigned(fBitmap) then fIEBitmap.EncapsulateTBitmap(fBitmap, true); if assigned(fBitmap) then begin fImageEnView := nil; fTImage := nil; end; end; {!! TImageEnIO.AttachedImageEn Declaration property AttachedImageEn: ; Description Use this property to attach a TImageEnIO to a , , or any other inherited component. This property is mutually exclusive with and . Note: TIEView is the base class of and . Example ImageEnIO1.AttachedImageEn := ImageEnView1; !!} procedure TImageEnIO.SetAttachedImageEn(atImageEn: TIEView); begin if assigned(fImageEnView) then fImageEnView.RemoveBitmapChangeEvent(fImageEnViewBitmapChangeHandle); // remove previous if exists fImageEnView := atImageEn; if assigned(fImageEnView) then begin // fImageEnView now could be nil if fIEBitmapCreated then begin fIEBitmapCreated := false; FreeAndNil(fIEBitmap); end; fBitmap := fImageEnView.Bitmap; fIEBitmap := fImageEnView.IEBitmap; if assigned(fIEBitmap) then // use TIEBitmap fBitmap := nil // both fBitmap and fIEBitmap not allowed else begin // use TBitmap fIEBitmapCreated := true; fIEBitmap := TIEBitmap.Create; fIEBitmap.EncapsulateTBitmap(fBitmap, true); end; fImageEnView.FreeNotification(self); fTImage := nil; fImageEnViewBitmapChangeHandle := fImageEnView.RegisterBitmapChangeEvent(OnBitmapChange); end else begin fIEBitmap := TIEBitmap.Create; fIEBitmapCreated := true; // we create fIEBitmap end; end; {!! TImageEnIO.AttachedTImage Declaration property AttachedTImage: TImage; Description Use this property to attach a TImageEnIO to a TImage (to widen its format support and functionality). This property is mutually exclusive with and . Example ImageEnIO1.AttachedTImage := Image1; !!} procedure TImageEnIO.SetTImage(v: TImage); begin if assigned(fImageEnView) then fImageEnView.RemoveBitmapChangeEvent(fImageEnViewBitmapChangeHandle); // remove previous if exists fTImage := v; if assigned(fTImage) then begin fBitmap := fTImage.Picture.Bitmap; fIEBitmap.EncapsulateTBitmap(fBitmap, true); fTImage.FreeNotification(self); fImageEnView := nil; end else fIEBitmap.FreeImage(true); end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // TIEIOThread {!! TImageEnIO.AsyncRunning Declaration property AsyncRunning: Integer; Description Returns the number of threads that are running. See also: Example // multithread saving Var Bmp: TIEBitmap; Io: TImageEnIO; Begin Bmp := TIEBitmap.Create; Io := TImageEnIO.CreateFromBitmap(bmp); Io.LoadFromFile('C:\input.bmp'); Io.AsyncMode := True; // this makes a thread foreach input/output task Io.SaveToFile('D:\i1.jpg'); // thread-1 Io.SaveToFile('D:\i2.jpg'); // thread-2 Io.SaveToFile('D:\i3.jpg'); // thread-3 // waits all threads finish Io.WaitThreads(); ... End; !!} function TImageEnIO.GetAsyncRunning: integer; begin fAsyncThreadsCS.Enter(); result := fAsyncThreads.Count; fAsyncThreadsCS.Leave(); end; procedure TIEIOThread.Init; begin fThreadList := fOwner.fAsyncThreads; fOwner.fAsyncThreadsCS.Enter(); fThreadList.Add(self); Windows.ResetEvent(fOwner.fAsyncThreadsFinishEvent); fOwner.fAsyncThreadsCS.Leave(); {$ifndef IEHASAFTERCONSTRUCTION} // this Delphi version hasn't AfterConstruction. We create threads in suspended mode, then resume Resume; {$endif} end; {$ifdef IEHASAFTERCONSTRUCTION} const TIEIOTHREAD_STARTMODE = false; // start in AfterConstruction (don't need Resume) {$else} const TIEIOTHREAD_STARTMODE = true; // start suspended (need Resume) {$endif} constructor TIEIOThread.CreateLoadSaveFile(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFile; const in_nf: WideString); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveFile; fMethod_LoadSaveFile := InMethod; p_nf := in_nf; Init; end; constructor TIEIOThread.CreateLoadSaveFileIF(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileIF; const in_nf: WideString; ImageFormat: TIOFileType); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveFileIF; fMethod_LoadSaveFileIF := InMethod; p_nf := in_nf; p_ImageFormat := ImageFormat; Init; end; constructor TIEIOThread.CreateLoadSaveStream(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStream; in_Stream: TStream); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveStream; fMethod_LoadSaveStream := InMethod; p_stream := in_Stream; Init; end; constructor TIEIOThread.CreateLoadSaveStreamRetInt(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamRetInt; in_Stream: TStream); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveStreamRetInt; fMethod_LoadSaveStreamRetInt := InMethod; p_stream := in_Stream; Init; end; constructor TIEIOThread.CreateLoadSaveStreamRetBool(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamRetBool; in_Stream: TStream); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveStreamRetBool; fMethod_LoadSaveStreamRetBool := InMethod; p_stream := in_Stream; Init; end; constructor TIEIOThread.CreateLoadSaveFileRetInt(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileRetInt; const in_nf: WideString); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveFileRetInt; fMethod_LoadSaveFileRetInt := InMethod; p_nf := in_nf; Init; end; constructor TIEIOThread.CreateLoadSaveFileRetBool(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileRetBool; const in_nf: WideString); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveFileRetBool; fMethod_LoadSaveFileRetBool := InMethod; p_nf := in_nf; Init; end; constructor TIEIOThread.CreateLoadSaveFileIFRetBool(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileIFRetBool; const in_nf: WideString; ImageFormat: TIOFileType); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveFileIFRetBool; fMethod_LoadSaveFileIFRetBool := InMethod; p_nf := in_nf; p_ImageFormat := ImageFormat; Init; end; constructor TIEIOThread.CreateLoadSaveFileFFRetBool(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveFileFFRetBool; const in_nf: WideString; in_fileformat: TIOFileType); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveFileFFRetBool; fMethod_LoadSaveFileFFRetBool := InMethod; p_nf := in_nf; p_fileformat := in_fileformat; Init; end; constructor TIEIOThread.CreateLoadSaveStreamFF(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamFF; in_Stream: TStream; in_fileformat: TIOFileType); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveStreamFF; fMethod_LoadSaveStreamFF := InMethod; p_stream := in_stream; p_fileformat := in_fileformat; Init; end; constructor TIEIOThread.CreateLoadSaveStreamFTRetBool(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveStreamFTRetBool; in_Stream: TStream; in_fileformat: TIOFileType); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveStreamFTRetBool; fMethod_LoadSaveStreamFTRetBool := InMethod; p_stream := in_stream; p_fileformat := in_fileformat; Init; end; constructor TIEIOThread.CreateCaptureFromScreen(Owner: TImageEnIO; InMethod: TIEIOMethodType_CaptureFromScreen; in_source: TIECSSource; in_mouseCursor: TCursor); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieCaptureFromScreen; fMethod_CaptureFromScreen := InMethod; p_source := in_source; p_mouseCursor := in_mouseCursor; Init; end; constructor TIEIOThread.CreateLoadSaveIndexRetBool(Owner: TImageEnIO; InMethod: TIEIOMethodType_LoadSaveIndexRetBool; in_index: integer); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadSaveIndexRetBool; fMethod_LoadSaveIndexRetBool := InMethod; p_index := in_index; Init; end; constructor TIEIOThread.CreateImportMetaFileRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_ImportMetaFileRetBool; const in_nf: WideString; in_width, in_height: integer; in_withalpha: boolean); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieImportMetaFileRetBool; fMethod_ImportMetaFileRetBool := InMethod; p_nf := in_nf; p_width := in_width; p_height := in_height; p_withalpha := in_withalpha; Init; end; constructor TIEIOThread.CreateLoadFromURLRetBool(owner: TImageEnIO; InMethod: TIEIOMethodType_LoadFromURLRetBool; const in_URL: WideString; dummy: Double); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieLoadFromURLRetBool; fMethod_LoadFromURLRetBool := InMethod; p_URL := in_URL; Init; end; constructor TIEIOThread.CreateAcquire(owner: TImageEnIO; InMethod: TIEIOMethodType_Acquire; bResetParams: Boolean); begin inherited Create(TIEIOTHREAD_STARTMODE); fOwner := Owner; fMethodType := ieAcquire; fMethod_Acquire := InMethod; p_ResetParams := bResetParams; Init; end; procedure TIEIOThread.Execute; begin fThreadID := GetCurrentThreadID; try case fMethodType of ieLoadSaveFile : fMethod_LoadSaveFile(p_nf); ieLoadSaveFileIF : fMethod_LoadSaveFileIF(p_nf, p_ImageFormat); ieLoadSaveStream : fMethod_LoadSaveStream(p_stream); ieLoadSaveFileRetInt : fMethod_LoadSaveFileRetInt(p_nf); ieLoadSaveFileRetBool : fMethod_LoadSaveFileRetBool(p_nf); ieLoadSaveFileIFRetBool : fMethod_LoadSaveFileIFRetBool(p_nf, p_ImageFormat); ieLoadSaveStreamRetInt : fMethod_LoadSaveStreamRetInt(p_stream); ieLoadSaveStreamRetBool : fMethod_LoadSaveStreamRetBool(p_stream); ieLoadSaveFileFFRetBool : fMethod_LoadSaveFileFFRetBool(p_nf, p_fileformat); ieLoadSaveStreamFF : fMethod_LoadSaveStreamFF(p_stream, p_FileFormat); ieLoadSaveStreamFTRetBool : fMethod_LoadSaveStreamFTRetBool(p_stream, p_FileFormat); ieCaptureFromScreen : fMethod_CaptureFromScreen(p_Source, p_mouseCursor); ieLoadSaveIndexRetBool : fMethod_LoadSaveIndexRetBool(p_index); ieImportMetaFileRetBool : fMethod_ImportMetaFileRetBool(p_nf, p_width, p_height, p_withalpha); ieLoadFromURLRetBool : fMethod_LoadFromURLRetBool(p_URL); ieAcquire : fMethod_Acquire(p_ResetParams); end; except fOwner.Aborting := true; end; FreeOnTerminate := true; fOwner.fAsyncThreadsCS.Enter(); fThreadList.Remove(self); if fThreadList.Count = 0 then Windows.SetEvent(fOwner.fAsyncThreadsFinishEvent); fOwner.fAsyncThreadsCS.Leave(); end; // end of TIEIOThread ///////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////// {!! TImageEnIO.LoadFromURL Declaration function LoadFromURL(const URL: WideString): Boolean; Description Loads the image from the internet using the HTTP or FTP protocol. Password authentication for HTTP is NOT supported, while it is necessary for FTP (even if connecting to an anonymous server). URL must be in the format: 'http://domain[:port]/resource' 'https://domain[:port]/resource' 'ftp://user:password@domain[:port]/resource' It is possible to set proxy parameters using , and properties. Example // load from standard port 80 ImageEnView.IO.LoadFromURL('http://www.imageen.com/image.jpg'); // load from port 8080 ImageEnView.IO.LoadFromURL('http://www.imageen.com:8080/image.jpg'); // load from FTP ImageEnView.IO.LoadFromURL('ftp://space:shuttle@ftp.imageen.com/Pictures/test.jpg') !!} function TImageEnIO.LoadFromURL(const URL: WideString): Boolean; var ms: TMemoryStream; FileExt: string; FileFormat: TIOFileType; begin Result := False; // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadFromURLRetBool(self, LoadFromURL, URL, 0); Result := True; exit; end; fAborting := false; ms := TMemoryStream.Create; try if not IEGetFromURL(URL, ms, IEGlobalSettings().ProxyAddress, IEGlobalSettings().ProxyUser, IEGlobalSettings().ProxyPassword, fOnIntProgress, self, @fAborting, FileExt) then begin fAborting := true; DoFinishWork; end else begin ms.Position := 0; FileFormat := FindStreamFormat( ms ); if FileFormat = ioUnknown then FileFormat := IEFilenameToFileFormat( URL ); Result := LoadFromStream( ms, FileFormat ); // this handles other tasks, such as IEBitmap sync, OnFinishWork, Update end; finally FreeAndNil(ms); end; end; // load from url ///////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TImageEnIO.DoAcquireBitmap(ABitmap: TIEBitmap; ImDpiX, ImDpiY: integer; var Handled: boolean); begin if assigned(fOnAcquireBitmap) then fOnAcquireBitmap(self, ABitmap, ImDpiX, ImDpiY, Handled); end; procedure TImageEnIO.TWMultiCallBack(Bitmap: TIEBitmap; var IOParams: TObject; ImDpiX, ImDpiY: integer); var bHandled: boolean; // Flag indicating whether the user has handled the acquired bitmap themselves begin if not MakeConsistentBitmap([]) then exit; bHandled := false; DoAcquireBitmap(Bitmap, ImDpiX, ImDpiY, bHandled); if not bHandled then begin IOParams := Params; fIEBitmap.Assign(Bitmap); if fAutoAdjustDPI then AdjustDPI; Update(); end; end; procedure TImageEnIO.TWCloseCallBack; begin fgrec := nil; if assigned(fOnAcquireClose) then fOnAcquireClose(self); end; {$IFDEF IEINCLUDEIEXACQUIRE} {!! TImageEnIO.TwainAcquireOpen Declaration function TwainAcquireOpen : boolean; Description Opens a connection to the selected scanner. It commonly used to perform a modeless acquisition from a Twain device. The result is false if it fails. Whenever ImageEn gets an image, the event occurs. See also: Demo Demos\ImageAcquisition\Twain\TwainDemo.dpr Example ImageEnIO.TwainAcquireOpen; ... ImageEnIO.TwainAcquireClose; !!} function TImageEnIO.TwainAcquireOpen: boolean; begin if (not assigned(fgrec)) and assigned(fImageEnView) then begin fAborting := false; fTwainParams.FreeResources; fTwainParams.LastError := 0; fTwainParams.LastErrorStr := ''; fgrec := IETWAINAcquireOpen(TWCloseCallBack, TWMultiCallBack, fTwainParams, @fTwainParams.TwainShared, fParams, fImageEnView, NativePixelFormat); result := fgrec <> nil; end else result := false; end; // Legacy interface to TwainAcquireOpen function TImageEnIO.AcquireOpen: boolean; begin result := TwainAcquireOpen; end; {$ENDIF} {$IFDEF IEINCLUDEIEXACQUIRE} {!! TImageEnIO.TwainAcquireClose Declaration procedure TwainAcquireClose; Description Closes a connection to a Twain device, which was opened with . Demo Demos\ImageAcquisition\Twain\TwainDemo.dpr Example ImageEnIO.TwainAcquireOpen; ... ImageEnIO.TwainAcquireClose; !!} procedure TImageEnIO.TwainAcquireClose; begin if fgrec <> nil then begin IETWAINAcquireClose(fgrec); fgrec := nil; end; end; // Legacy interface to TwainAcquireClose procedure TImageEnIO.AcquireClose; begin TwainAcquireClose; end; {$ENDIF} //////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////// {!! TImageEnIO.ThreadsCount Declaration property ThreadsCount: Integer; Description Returns the count of currently active threads. Valid only if is True. !!} function TImageEnIO.GetThreadsCount: integer; begin fAsyncThreadsCS.Enter(); result := fAsyncThreads.Count; fAsyncThreadsCS.Leave(); end; {!! TImageEnIO.DefaultDitherMethod Declaration property DefaultDitherMethod: ; Description Specifies the dithering method to apply when a color image needs to be converted to black/white. Default: ieThreshold !!} procedure TImageEnIO.SetDefaultDitherMethod(Value: TIEDitherMethod); begin if assigned(fIEBitmap) then fIEBitmap.DefaultDitherMethod := Value; fDefaultDitherMethod := Value; end; {!! TImageEnIO.Bitmap Declaration property Bitmap: TBitmap; (Read-only) Description References the bitmap contained in TImageEnIO, or . Example // Use the standard LoadFromFile method of TBitmap ImageEnView1.IO.Bitmap.LoadFromFile('C:\my.bmp'); ImageEnView1.IO.Bitmap.PixelFormat := pf24bit; ImageEnView1.Update; !!} function TImageEnIO.GetBitmap: TBitmap; begin if assigned(fIEBitmap) and (fIEBitmap.Location = ieTBitmap) then result := fIEBitmap.VclBitmap else result := fBitmap; end; {!! TImageEnIO.SaveToStreamICO Declaration procedure SaveToStreamICO(Stream: TStream); Description Saves the current image to a stream in ICO format. ICO format allows storing multiple images with several resolutions and sizes. ImageEn creates for you the sub-images to save; you have only to set the . and Params. arrays. To control each image separately, use the function. Example // save the current image in 'output.ico', It will contain three images with 64x64 32bit (24bit +alphachannel), 32x32 256 colors and 32x32 16 colors // 64x64 x32bit ImageEnView.IO.Params.ICO.BitCount[0] := 32; ImageEnView.IO.Params.ICO.Sizes[0].cx := 64; ImageEnView.IO.Params.ICO.Sizes[0].cy := 64; // 32x32 x8bit ImageEnView.IO.Params.ICO.BitCount[1] := 8; ImageEnView.IO.Params.ICO.Sizes[1].cx := 32; ImageEnView.IO.Params.ICO.Sizes[1].cy := 32; // 32x32 x4bit ImageEnView.IO.Params.ICO.BitCount[2] := 4; ImageEnView.IO.Params.ICO.Sizes[2].cx := 32; ImageEnView.IO.Params.ICO.Sizes[2].cy := 32; // I don't want other images ImageEnView.IO.Params.ICO.BitCount[3] := 0; ImageEnView.IO.Params.ICO.Sizes[3].cx := 0; ImageEnView.IO.Params.ICO.Sizes[3].cy := 0; // save ImageEnView.IO.SaveToFile('D:\output.ico'); !!} procedure TImageEnIO.SaveToStreamICO(Stream: TStream); var Progress: TProgressRec; icount: integer; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamICO, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; icount := 0; while (icount <= high(Params.ICO_Sizes)) and (Params.ICO_Sizes[icount].cx > 0) do inc(icount); ICOWriteStream(Stream, fIEBitmap, fParams, Progress, slice(Params.ICO_Sizes, icount), slice(Params.ICO_BitCount, icount)); finally DoFinishWork; end; end; {!! TImageEnIO.SaveToFileICO Declaration procedure SaveToFileICO(const FileName: WideString); Description Saves the current image to a file in ICO format. ICO format allows storing multiple images with different resolutions and sizes. FileName is the file name including extension. ImageEn creates for you the sub-images to save, you have only to set the . and Params. arrays. To control each image separately, use the function. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Demo Demos\FullApps\PlainIconEditor\PlainIconEditor.dpr Example // save the current image in 'output.ico', It will contain three images with 64x64 32bit (24bit +alphachannel), 32x32 256 colors and 32x32 16 colors // 64x64 x32bit ImageEnView.IO.Params.ICO.BitCount[0] := 32; ImageEnView.IO.Params.ICO.Sizes[0].cx := 64; ImageEnView.IO.Params.ICO.Sizes[0].cy := 64; // 32x32 x8bit ImageEnView.IO.Params.ICO.BitCount[1] := 8; ImageEnView.IO.Params.ICO.Sizes[1].cx := 32; ImageEnView.IO.Params.ICO.Sizes[1].cy := 32; // 32x32 x4bit ImageEnView.IO.Params.ICO.BitCount[2] := 4; ImageEnView.IO.Params.ICO.Sizes[2].cx := 32; ImageEnView.IO.Params.ICO.Sizes[2].cy := 32; // I don't want other images ImageEnView.IO.Params.ICO.BitCount[3] := 0; ImageEnView.IO.Params.ICO.Sizes[3].cx := 0; ImageEnView.IO.Params.ICO.Sizes[3].cy := 0; // save ImageEnView.IO.SaveToFile('D:\output.ico'); !!} procedure TImageEnIO.SaveToFileICO(const FileName: WideString); var Progress: TProgressRec; fs: TIEWideFileStream; icount: integer; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileICO, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try icount := 0; while (icount <= high(Params.ICO_Sizes)) and (Params.ICO_Sizes[icount].cx > 0) do inc(icount); ICOWriteStream(fs, fIEBitmap, fParams, Progress, slice(Params.ICO_Sizes, icount), slice(Params.ICO_BitCount, icount)); fParams.FileName := FileName; fParams.FileType := ioICO; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {$IFDEF IEINCLUDEIEXACQUIRE} {!! TImageEnIO.WIAParams Declaration property WIAParams: ; Description Provides access to WIA parameters and allows you to show dialogs and control WIA devices. Note: Use WIAParams only when you need access to WIA specific functionality (when .Api is ieaWIA). For generic access to all image acquisitions sources (Twain, WIA, etc.) use instead. Demo Demos\ImageAcquisition\WIAScanner\WIAScanner.dpr Examples // select first device, set black/white (with threshold) and capture ImageEnView.IO.WIAParams.SetItemProperty(WIA_IPA_DATATYPE, WIA_DATA_THRESHOLD, nil); if ImageEnView1.IO.SetSource(ieaWIA, Default_Device) then ImageEnView1.IO.Acquire; // set dpi = 150 then capture ImageEnView.IO.WIAParams.SetItemProperty(WIA_IPS_XRES, 150, nil); ImageEnView.IO.WIAParams.SetItemProperty(WIA_IPS_YRES, 150, nil); if ImageEnView1.IO.SetSource(ieaWIA, Default_Device) then ImageEnView1.IO.Acquire; See Also - - - !!} function TImageEnIO.GetWIAParams: TIEWia; begin if not assigned(fWIA) then begin fWIA := TIEWia.Create(self); fWIA.OnProgress := WiaOnProgress; end; result := fWIA; end; function TImageEnIO.WiaOnProgress(Percentage: integer): boolean; begin fOnIntProgress(self, Percentage); // fOnIntProgress is always assigned result := not fAborting; end; {$ENDIF} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TImageEnIO.SyncLoadFromStreamWBMP(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; WBMPReadStream(Stream, fIEBitmap, fParams, Progress, false); CheckDPI; fParams.FileName := ''; fParams.FileType := ioWBMP; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromFileWBMP Declaration function LoadFromFileWBMP(const FileName: WideString): Boolean; Description Loads an image from a WBMP (Wireless bitmap) file. FileName is the file name including extension. Result will be false if the file is not WBMP format (and will be false). Loading errors due to a file not being available will raise an exception. !!} function TImageEnIO.LoadFromFileWBMP(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileWBMP, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamWBMP( fs ); fParams.FileName := Filename; finally FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamWBMP Declaration function LoadFromStreamWBMP(Stream: TStream): Boolean; Description Loads an image from a stream containing a WBMP (Wireless bitmap) file. The result will be false if an error is encountered, e.g. the file in the stream is not WBMP format ( will be true). !!} function TImageEnIO.LoadFromStreamWBMP(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamWBMP, Stream); Result := True; end else begin Result := SyncLoadFromStreamWBMP( Stream ); end; end; {!! TImageEnIO.SaveToFileWBMP Declaration procedure SaveToFileWBMP(const FileName: WideString); Description Saves the current image to a file in WBMP (Wireless bitmap) format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. !!} procedure TImageEnIO.SaveToFileWBMP(const FileName: WideString); var Progress: TProgressRec; fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileWBMP, FileName); exit; end; try fAborting := true; // So that fAborting is True if the file is not found Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fs := TIEWideFileStream.Create(FileName, fmCreate); fAborting := false; try WBMPWriteStream(fs, fIEBitmap, fParams, Progress); fParams.FileName := FileName; fParams.FileType := ioWBMP; finally FreeAndNil(fs); end; finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamWBMP Declaration procedure SaveToStreamWBMP(Stream: TStream); Description Saves the current image to a stream in WBMP (Wireless bitmap) format. !!} procedure TImageEnIO.SaveToStreamWBMP(Stream: TStream); var Progress: TProgressRec; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveStream(self, SaveToStreamWBMP, Stream); exit; end; try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; WBMPWriteStream(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {!! TImageEnIO.CreatePSFile Declaration procedure CreatePSFile(const FileName: WideString); Description Creates a new, empty PostScript file of the specified filename. You can add pages using and when complete, close the file using . Note: All images in the resulting PostScript file will be aligned to the upper-left corner of the paper. Demo Demos\InputOutput\PDFBuilder\PdfBuilder.dpr Example ImageEnView1.IO.CreatePSFile( 'D:\output.ps' ); // load and save page 1 ImageEnView1.IO.LoadFromFile('C:\page1.tiff'); ImageEnView1.IO.Params.PS_Compression := ioPS_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPS; // load and save page 2 ImageEnView1.IO.LoadFromFile('C:\page2.tiff'); ImageEnView1.IO.Params.PS_Compression := ioPS_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPS; ...Other pages... // close PS file ImageEnView1.IO.ClosePSFile; !!} procedure TImageEnIO.CreatePSFile(const FileName: WideString); begin fAborting := False; fPS_stream := TIEWideFileStream.Create(FileName, fmCreate); fPS_handle := IEPostScriptCreate(fPS_stream, fParams); end; {!! TImageEnIO.SaveToPS Declaration procedure SaveToPS; Description Saves the current image to a PostScript file opened using . Note: All images in the resulting PostScript file will be aligned to the upper-left corner of the paper. Demo Demos\InputOutput\PDFBuilder\PdfBuilder.dpr Example ImageEnView1.IO.CreatePSFile( 'D:\output.ps' ); // load and save page 1 ImageEnView1.IO.LoadFromFile('C:\page1.tiff'); ImageEnView1.IO.Params.PS_Compression := ioPS_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPS; // load and save page 2 ImageEnView1.IO.LoadFromFile('C:\page2.tiff'); ImageEnView1.IO.Params.PS_Compression := ioPS_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPS; ...Other pages... // close PS file ImageEnView1.IO.ClosePSFile; !!} procedure TImageEnIO.SaveToPS; var Progress: TProgressRec; begin if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); IEPostScriptSave(fPS_handle, fPS_stream, fIEBitmap, fParams, Progress); end; {!! TImageEnIO.ClosePSFile Declaration procedure ClosePSFile; Description Closes a PostScript file opened using . Demo Demos\InputOutput\PDFBuilder\PdfBuilder.dpr Example ImageEnView1.IO.CreatePSFile( 'output.ps' ); // load and save page 1 ImageEnView1.IO.LoadFromFile('C:\page1.tiff'); ImageEnView1.IO.Params.PS_Compression := ioPS_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPS; // load and save page 2 ImageEnView1.IO.LoadFromFile('C:\page2.tiff'); ImageEnView1.IO.Params.PS_Compression := ioPS_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPS; ...Other pages... // close PS file ImageEnView1.IO.ClosePSFile; See Also - - !!} procedure TImageEnIO.ClosePSFile; begin if fPS_handle <> nil then IEPostScriptClose(fPS_handle, fPS_stream); if assigned(fPS_stream) then FreeAndNil(fPS_stream); fPS_stream := nil; fPS_handle := nil; end; procedure TImageEnIO.SyncSaveToStreamPS(Stream: TStream); var Progress: TProgressRec; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; IEPostScriptSaveOneStep(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamPS Declaration procedure SaveToStreamPS(Stream: TStream); Description Saves the current image to a stream in PostScript format. The resulting file will have only one page. !!} procedure TImageEnIO.SaveToStreamPS(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamPS, Stream); end else begin SyncSaveToStreamPS(Stream); end; end; {!! TImageEnIO.SaveToFilePS Declaration procedure SaveToFilePS(const FileName: WideString); Description Saves the current image to a file in PostScript format. FileName is the file name including extension. If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Note: The created file will have only one page. See to create multi-page PS files. Example ImageEnView1.IO.LoadFromFile('D:\input.bmp'); ImageEnView1.IO.SaveToFilePS('D:\output.ps'); !!} procedure TImageEnIO.SaveToFilePS(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFilePS, FileName); exit; end; fs := TIEWideFileStream.Create(FileName, fmCreate); try SyncSaveToStreamPS(fs); fParams.FileName := FileName; fParams.FileType := ioPS; finally FreeAndNil(fs); end; end; {!! TImageEnIO.CreatePDFFile Declaration procedure CreatePDFFile(const FileName: WideString); Description Creates a new, empty Adobe PDF file of the specified filename. You can add pages using and when complete, close the file using . Note: All images in the resulting PDF file will be aligned to the upper-left corner of the paper. Demo Demos\InputOutput\PDFBuilder\PdfBuilder.dpr Example ImageEnView1.IO.CreatePDFFile( 'D:\output.pdf' ); // load and save page 1 ImageEnView1.IO.LoadFromFile('C:\page1.tiff'); ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPDF; // load and save page 2 ImageEnView1.IO.LoadFromFile('C:\page2.tiff'); ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPDF; ...Other pages... // close PDF file ImageEnView1.IO.ClosePDFFile; !!} {$ifdef IEINCLUDEPDFWRITING} procedure TImageEnIO.CreatePDFFile(const FileName: WideString); begin fAborting := False; fPDF_stream := TIEWideFileStream.Create(FileName, fmCreate); fPDF_handle := IEPDFCreate(fParams); end; {$endif} {!! TImageEnIO.SaveToPDF Declaration procedure SaveToPDF; Description Saves the current image to the active Adobe PDF file, opened using . Note: All images in the resulting PDF file will be aligned to the upper-left corner of the paper. Demo Demos\InputOutput\PDFBuilder\PdfBuilder.dpr Example ImageEnView1.IO.CreatePDFFile( 'D:\output.pdf' ); // load and save page 1 ImageEnView1.IO.LoadFromFile('C:\page1.tiff'); ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPDF; // load and save page 2 ImageEnView1.IO.LoadFromFile('C:\page2.tiff'); ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPDF; ...Other pages... // close PDF file ImageEnView1.IO.ClosePDFFile; !!} {$ifdef IEINCLUDEPDFWRITING} procedure TImageEnIO.SaveToPDF; var Progress: TProgressRec; begin if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); IEPDFSave(fPDF_handle, fIEBitmap, fParams, Progress); end; {$endif} {!! TImageEnIO.ClosePDFFile Declaration procedure ClosePDFFile; Description Closes the active Adobe PDF file, opened using . Demo Demos\InputOutput\PDFBuilder\PdfBuilder.dpr Example ImageEnView1.IO.CreatePDFFile( 'D:\output.pdf' ); // load and save page 1 ImageEnView1.IO.LoadFromFile('C:\page1.tiff'); ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPDF; // load and save page 2 ImageEnView1.IO.LoadFromFile('C:\page2.tiff'); ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression ImageEnView1.IO.SaveToPDF; ...Other pages... // close PDF file ImageEnView1.IO.ClosePDFFile; See Also - - !!} {$ifdef IEINCLUDEPDFWRITING} procedure TImageEnIO.ClosePDFFile; begin if fPDF_handle <> nil then IEPDFClose(fPDF_handle, fPDF_stream, fParams); if assigned(fPDF_stream) then FreeAndNil(fPDF_stream); fPDF_stream := nil; fPDF_handle := nil; end; {$endif} {$ifdef IEINCLUDEPDFWRITING} procedure TImageEnIO.SyncSaveToStreamPDF(Stream: TStream); var Progress: TProgressRec; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if (fIEBitmap.pixelformat <> ie24RGB) and (fIEBitmap.PixelFormat <> ie1g) then fIEBitmap.PixelFormat := ie24RGB; IEPDFSaveOneStep(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {$endif} {!! TImageEnIO.SaveToStreamPDF Declaration procedure SaveToStreamPDF(Stream: TStream); Description Saves the current image to a stream in Adobe PDF format. The resulting file will have only one page. !!} {$ifdef IEINCLUDEPDFWRITING} procedure TImageEnIO.SaveToStreamPDF(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamPDF, Stream); end else begin SyncSaveToStreamPDF(Stream); end; end; {$endif} {!! TImageEnIO.SaveToFilePDF Declaration procedure SaveToFilePDF(const FileName: WideString); Description Saves the current image to a file in Adobe PDF format. FileName is the file name including extension. If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Note: The created file will have only one page. See to create multi-page PDF files. Example ImageEnView1.IO.LoadFromFile('C:\input.bmp'); ImageEnView1.IO.SaveToFilePDF('D:\output.pdf'); !!} {$ifdef IEINCLUDEPDFWRITING} procedure TImageEnIO.SaveToFilePDF(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFilePDF, FileName); exit; end; fs := TIEWideFileStream.Create(FileName, fmCreate); try SyncSaveToStreamPDF(fs); fParams.FileName := FileName; fParams.FileType := ioPDF; finally FreeAndNil(fs); end; end; {$endif} {$IFDEF IEINCLUDEDIRECTSHOW} {!! TImageEnIO.DShowParams Declaration property DShowParams: ; Description DShowParams is a TIEDirectShow instance which allows control of some Direct Show features, such as video capture, audio capture, multimedia files capture as well video rendering, and multimedia file writing. Demos Demos\VideoCapture\DirectShow1\DShow.dpr Demos\VideoCapture\DirectShow2\DShowCap.dpr Demos\VideoCapture\VideoEffects\VideoEffects.dpr Demos\Display\VideoPlayer\VideoPlayer.dpr Examples Capture Skeleton // Fills ComboBox1 with the names of all video capture inputs ComboBox1.Items.Assign( ImageEnView1.IO.DShowParams.VideoInputs ); // Select the first video input available ImageEnView1.IO.DShowParams.SetVideoInput( 0 ); // Enables frame grabbing // ImageEnView1.OnDShowNewFrame event occurs for each frame acquired ImageEnView1.IO.DShowParams.EnableSampleGrabber := True; // connect to the video input: this begins video capture ImageEnView1.IO.DShowParams.Connect; ... // Disconnect the video input ImageEnView1.IO.DShowParams.Disconnect; Capture a frame // We are inside the OnDShowNewFrame event: procedure Tfmain.ImageEnView1DShowNewFrame(Sender: TObject); begin // copy current sample to ImageEnView bitmap ImageEnView1.IO.DShowParams.GetSample(ImageEnView1.IEBitmap); // refresh ImageEnView1 ImageEnView1.Update; end; Setting video capture size // We'd like to acquire 640x480 frames ImageEnView1.IO.DShowParams.SetCurrentVideoFormat( 640, 480, '' ); Select a TV Tuner channel // We want channel 15 ImageEnView1.IO.DShowParams.TunerChannel := 15; Showing capture card dialogs // Show video dialog ImageEnView1.IO.DShowParams.ShowPropertyPages(iepVideoInput, ietFilter); // Show video source dialog ImageEnView1.IO.DShowParams.ShowPropertyPages(iepVideoInputSource, ietFilter); // Show tuner dialog ImageEnView1.IO.DShowParams.ShowPropertyPages(iepTuner, ietFilter); // Show format dialog ImageEnView1.IO.DShowParams.ShowPropertyPages(iepVideoInput, ietOutput); Read from a multimedia file, and save with another compression ImageEnView1.IO.DShowParams.FileInput := 'input.avi'; ImageEnView1.IO.DShowParams.FileOutput := 'output.avi'; ImageEnView1.IO.DShowParams.SetVideoCodec( ... ); ImageEnView1.IO.DShowParams.SetAudioCodec( ... ); ImageEnView1.IO.DShowParams.EnableSampleGrabber := True; ImageEnView1.IO.DShowParams.Connect; See the \VideoCapture\DirectShow1\ and \VideoCapture\DirectShow2\ demos for more info. !!} function TImageEnIO.GetDShowParams: TIEDirectShow; begin if not assigned(fDShow) then begin fDShow := TIEDirectShow.Create; if assigned(fImageEnView) then begin fDShow.SetNotifyWindow(fImageEnView.Handle, IEM_NEWFRAME, IEM_EVENT) end; end; result := fDShow; end; {$ENDIF} {$IFDEF IEINCLUDEMEDIAFOUNDATION} {!! TImageEnIO.MediaFoundationSourceReader Declaration property MediaFoundationSourceReader: ; Description MediaFoundationSourceReader is a TIEMediaFoundationSourceReader instance which allows capture samples from webcams, multimedia files and URLs. This is a minimal setup to capture from a webcam (the first webcam, using first proposed media type): ImageEnView1.IO.MediaFoundationSourceReader.SetVideoInput(0); // select first video input (first webcam) ImageEnView1.IO.MediaFoundationSourceReader.SetSelectedStreams('Video', true); // enable first video stream ImageEnView1.IO.MediaFoundationSourceReader.SelectMediaType('Video', 0); // select first media type of the first video stream ImageEnView1.IO.MediaFoundationSourceReader.StartCapture(); // start capture // handler for TImageEnView.OnMediaFoundatioNotify event procedure TForm1.ImageEnVect1MediaFoundationNotify(Sender, MediaFoundationObject: TObject; NotifyType: TIEMediaFountationNotifyType); var sample: TIEMFReceivedSample; begin if NotifyType = iemfnFRAME then // is this a frame? begin sample := ImageEnView1.IO.MediaFoundationSourceReader.GetNextSample(); // retrieve frame sample try sample.DecodeSample(ImageEnView1.IEBitmap); // convert frame sample to bitmap ImageEnView1.Update(); // update TImageEnView to show the new bitmap finally sample.Free(); // free the sample end; end; end; Look at VideoCapture\MediaFoundation demos for usage samples. !!} function TImageEnIO.GetMediaFoundationSourceReader(): TIEMediaFoundationSourceReader; begin if not assigned(fMediaFoundationSourceReader) then begin fMediaFoundationSourceReader := TIEMediaFoundationSourceReader.Create(); if assigned(fImageEnView) then fMediaFoundationSourceReader.PushNotifyReceiver( TIEMediaFoundationReaderWindowNotifyReceiver.Create(fImageEnView.Handle, IEM_MEDIAFOUNDATION) ); end; result := fMediaFoundationSourceReader; end; {$ENDIF} procedure TImageEnIO.CheckDPI; begin if fParams.DpiX < 2 then fParams.DpiX := IEGlobalSettings().DefaultDPIX; if fParams.DpiY < 2 then fParams.DpiY := IEGlobalSettings().DefaultDPIY; end; {$ifdef IEINCLUDERAWFORMATS} function TImageEnIO.SyncLoadFromStreamRAW(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; IEReadCameraRAWStream(Stream, fIEBitmap, fParams, Progress, false); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioRAW; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {$endif} {$ifdef IEINCLUDERAWFORMATS} {!! TImageEnIO.LoadFromStreamRAW Declaration function LoadFromStreamRAW(Stream: TStream): Boolean; Description Loads an image from a stream containing a digital camera Raw file. The result will be false if an error is encountered, e.g. the file in the stream is not a RAW format ( will be true). !!} function TImageEnIO.LoadFromStreamRAW(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamRAW, Stream); Result := True; end else begin Result := SyncLoadFromStreamRAW(Stream); end; end; {$endif} {$ifdef IEINCLUDERAWFORMATS} {!! TImageEnIO.LoadFromFileRAW Declaration function LoadFromFileRAW(const FileName: WideString): Boolean; Description Loads an image from a Digital Camera Raw file. FileName is the file name including extension. Result will be false if the file is not a camera RAW format (and will be false). Loading errors due to a file not being available will raise an exception. Demo Demos\InputOutput\CameraRaw\CameraRaw.dpr !!} function TImageEnIO.LoadFromFileRAW(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileRAW, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamRAW(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {$endif} {$ifdef IEINCLUDEDIRECTSHOW} {!! TImageEnIO.OpenMediaFile Declaration function OpenMediaFile(const FileName: WideString): Integer; Description Opens a video file using DirectShow. Supported file types are AVI, MPEG, WMV and other DirectX supported formats. This method will open the file, but doesn't actually get an image. To get a frame use the method. To close the media file use . Example // Save frame 10 as 'frame10.jpg' ImageEnView1.IO.OpenMediaFile('C:\film.mpeg'); ImageEnView1.IO.LoadFromMediaFile(10); ImageEnView1.IO.SaveToFile('D:\frame10.jpg'); ImageEnView1.IO.CloseMediaFile; !!} function TImageEnIO.OpenMediaFile(const FileName: WideString): Integer; var l: int64; ww, hh: Integer; fmt: AnsiString; avgtime, ltime: int64; begin result := 0; if assigned(fOpenMediaFile) then CloseMediaFile; fAborting := True; fOpenMediaFile := TIEDirectShow.Create; fOpenMediaFile.FileInput := AnsiString(FileName); fOpenMediaFile.EnableSampleGrabber := True; fOpenMediaFile.Connect; fOpenMediaFile.Pause; fOpenMediaFile.TimeFormat := TfTime; ltime := fOpenMediaFile.Duration; if (ltime = 0) then exit; fOpenMediaFile.TimeFormat := TfFrame; l := fOpenMediaFile.Duration; avgtime := fOpenMediaFile.GetAverageTimePerFrame; if (l=ltime) and (avgtime <> 0) then begin l := l div avgtime; fOpenMediaFileMul := avgtime; end else fOpenMediaFileMul := 1; fOpenMediaFileRate := (ltime/10000000) / l*1000; fAborting := False; fParams.MEDIAFILE_FrameCount := l; fParams.FileType := ioUnknown; ResetModified(); fParams.FileName := FileName; // this is important for TImageEnMView fOpenMediaFile.GetCurrentVideoFormat(ww, hh, fmt); fParams.Width := ww; fParams.Height := hh; fParams.OriginalWidth := ww; fParams.OriginalHeight := hh; result := l; end; {!! TImageEnIO.CloseMediaFile Declaration procedure CloseMediaFile; Description Close a video file that was opened with . Example // Save frame 10 as 'frame10.jpg' ImageEnView1.IO.OpenMediaFile('C:\film.mpeg'); ImageEnView1.IO.LoadFromMediaFile(10); ImageEnView1.IO.SaveToFile('D:\frame10.jpg'); ImageEnView1.IO.CloseMediaFile; !!} procedure TImageEnIO.CloseMediaFile; begin if assigned(fOpenMediaFile) then begin fOpenMediaFile.Disconnect; FreeAndNil(fOpenMediaFile); end; end; {!! TImageEnIO.LoadFromMediaFile Declaration procedure LoadFromMediaFile(FrameIndex: Integer); Description Loads the specified frame from a media file that was opened using . The first frame has index 0. Example // Save frame 10 as 'frame10.jpg' ImageEnView1.IO.OpenMediaFile('C:\film.mpeg'); ImageEnView1.IO.LoadFromMediaFile(10); ImageEnView1.IO.SaveToFile('D:\frame10.jpg'); ImageEnView1.IO.CloseMediaFile; !!} procedure TImageEnIO.LoadFromMediaFile(FrameIndex: Integer); begin CheckHaveValidBitmap(); if assigned(fOpenMediaFile) then begin fParams.TIFF_ImageIndex := FrameIndex; fParams.GIF_ImageIndex := FrameIndex; fParams.DCX_ImageIndex := FrameIndex; fOpenMediaFile.position := int64(FrameIndex) * int64(fOpenMediaFileMul); fOpenMediaFile.GetSample( fIEBitmap ); fParams.MEDIAFILE_FrameDelayTime := fOpenMediaFileRate; Update(); ResetModified(); end; end; {!! TImageEnIO.IsOpenMediaFile Declaration function IsOpenMediaFile: Boolean; Description Returns True if has a currently open file. !!} function TImageEnIO.IsOpenMediaFile: Boolean; begin result := assigned(fOpenMediaFile); end; {$endif} function TImageEnIO.SyncLoadFromStreamBMPRAW(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; IERealRAWReadStream(Stream, fIEBitmap, fParams, Progress); fParams.FileName := ''; fParams.FileType := ioBMPRAW; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; {!! TImageEnIO.LoadFromStreamBMPRAW Declaration function LoadFromStreamBMPRAW(Stream: TStream): Boolean; Description Loads an image from a stream containing a BmpRaw file. The result will be false if an error is encountered, e.g. the file in the stream is not BmpRaw format ( will be true). Note: This is not the same as a digital camera Raw file, but a true "raw" format (named "BmpRaw" in ImageEn) where you can specify the channel order, placement, alignment, size, etc. Demo Demos\InputOutput\RealRAW\RealRaw.dpr Examples // load a RAW image, RGB, interleaved, 8 bit aligned, 1024x768 ImageEnView1.LegacyBitmap := False; ImageEnView1.IEBitmap.Allocate(1024, 768, ie24RGB); ImageEnView1.IO.Params.BMPRAW_ChannelOrder := coRGB; ImageEnView1.IO.Params.BMPRAW_Planes := plInterleaved; ImageEnView1.IO.Params.BMPRAW_RowAlign := 8; ImageEnView1.IO.Params.BMPRAW_HeaderSize := 0; ImageEnView1.IO.LoadFromStreamBMPRAW( stream ); // load a RAW image, CMYK, interleaved, 8 bit aligned, 1024x768 ImageEnView1.LegacyBitmap := False; ImageEnView1.IEBitmap.Allocate(1024, 768, ieCMYK); ImageEnView1.IO.Params.BMPRAW_ChannelOrder := coRGB; ImageEnView1.IO.Params.BMPRAW_Planes := plInterleaved; ImageEnView1.IO.Params.BMPRAW_RowAlign := 8; ImageEnView1.IO.Params.BMPRAW_HeaderSize := 0; ImageEnView1.IO.LoadFromStreamBMPRAW( stream ); !!} function TImageEnIO.LoadFromStreamBMPRAW(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamBMPRAW, Stream); Result := True; end else begin Result := SyncLoadFromStreamBMPRAW(Stream); end; end; {!! TImageEnIO.LoadFromFileBMPRAW Declaration function LoadFromFileBMPRAW(const FileName: WideString): Boolean; Description Loads an image from a BmpRaw file. FileName is the file name including extension. Result will be false if the file is not BmpRaw (and will be false). Loading errors due to a file not being available will raise an exception. Note: This is not the same as a digital camera Raw file, but a true "raw" format (named "BmpRaw" in ImageEn) where you can specify the channel order, placement, alignment, size, etc. Demo Demos\InputOutput\RealRAW\RealRaw.dpr Examples // load a RAW image, RGB, interleaved, 8 bit aligned, 1024x768 ImageEnView1.LegacyBitmap := False; ImageEnView1.IEBitmap.Allocate(1024, 768, ie24RGB); ImageEnView1.IO.Params.BMPRAW_ChannelOrder := coRGB; ImageEnView1.IO.Params.BMPRAW_Planes := plInterleaved; ImageEnView1.IO.Params.BMPRAW_RowAlign := 8; ImageEnView1.IO.Params.BMPRAW_HeaderSize := 0; ImageEnView1.IO.LoadFromFileBMPRAW('C:\input.dat'); // load a RAW image, CMYK, interleaved, 8 bit aligned, 1024x768 ImageEnView1.LegacyBitmap := False; ImageEnView1.IEBitmap.Allocate(1024, 768, ieCMYK); ImageEnView1.IO.Params.BMPRAW_ChannelOrder := coRGB; ImageEnView1.IO.Params.BMPRAW_Planes := plInterleaved; ImageEnView1.IO.Params.BMPRAW_RowAlign := 8; ImageEnView1.IO.Params.BMPRAW_HeaderSize := 0; ImageEnView1.IO.LoadFromFileBMPRAW('C:\input.dat'); !!} function TImageEnIO.LoadFromFileBMPRAW(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileBMPRAW, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamBMPRAW(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; procedure TImageEnIO.SyncSaveToStreamBMPRAW(Stream: TStream); var Progress: TProgressRec; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; IERealRAWWriteStream(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {!! TImageEnIO.SaveToStreamBMPRAW Declaration procedure SaveToStreamBMPRAW(Stream: TStream); Description Saves the current image to a stream in BmpRaw format. Note: This is not the same as a digital camera Raw file, but a true "raw" format (named "BmpRaw" in ImageEn) where you can specify the channel order, placement, alignment, size, etc. Demo Demos\InputOutput\RealRAW\RealRaw.dpr Example // saves current image as RAW image ImageEnView1.IO.Params.BMPRAW_ChannelOrder := coRGB; ImageEnView1.IO.Params.BMPRAW_Planes := plPlanar; ImageEnView1.IO.Params.BMPRAW_RowAlign := 8; ImageEnView1.IO.SaveToStreamBMPRAW(stream); !!} procedure TImageEnIO.SaveToStreamBMPRAW(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamBMPRAW, Stream); end else begin SyncSaveToStreamBMPRAW(Stream); end; end; {!! TImageEnIO.SaveToFileBMPRAW Declaration procedure SaveToFileBMPRAW(const FileName: WideString); Description Saves the current image to a file in BmpRaw format. FileName is the file name including extension. If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Note: This is not the same as a digital camera Raw file, but a true "raw" format (named "BmpRaw" in ImageEn) where you can specify the channel order, placement, alignment, size, etc. Demo Demos\InputOutput\RealRAW\RealRaw.dpr Example // saves current image as RAW image ImageEnView1.IO.Params.BMPRAW_ChannelOrder := coRGB; ImageEnView1.IO.Params.BMPRAW_Planes := plPlanar; ImageEnView1.IO.Params.BMPRAW_RowAlign := 8; ImageEnView1.IO.SaveToFileBMPRAW('C:\output.dat'); !!} procedure TImageEnIO.SaveToFileBMPRAW(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); if FileName='' then exit; // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileBMPRAW, FileName); exit; end; fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmCreate); SyncSaveToStreamBMPRAW(fs); fParams.FileName := FileName; fParams.FileType := ioBMPRAW; finally FreeAndNil(fs); end; end; {$ifdef IEINCLUDERAWFORMATS} {!! TImageEnIO.LoadJpegFromFileCRW Declaration function LoadJpegFromFileCRW(const FileName: WideString): Boolean; Description Extract and load the large Jpeg encapsulated inside a CRW (Canon RAW) file. Result will be false if the file is not a recognized file type (and will be false). Loading errors due to a file not being available will raise an exception. Example ImageEnView1.IO.LoadJpegFromFileCRW('C:\input.crw'); !!} function TImageEnIO.LoadJpegFromFileCRW(const FileName: WideString): Boolean; var Progress: TProgressRec; fs: TIEWideFileStream; begin Result := False; if FileName='' then exit; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; IECRWGetJpeg(fIEBitmap, fs); fParams.FileName := FileName; fParams.FileType := ioRAW; Update(); finally FreeAndNil(fs); DoFinishWork; Result := Not fAborting; end; end; {$endif} procedure TImageEnIO.DoIntProgress(Sender: TObject; per: integer); begin if assigned(fOnProgress) then begin if assigned(fImageEnView) and (fImageEnView.Parent <> nil) and IsInsideAsyncThreads then begin // we are inside a thread, so send a message to the parent TImageEnView component, if exists {$ifdef IEHASTTHREADSTATICSYNCHRONIZE} if not fImageEnView.HandleAllocated then // 3.0.2, to avoid deadlocks TThread.Synchronize(nil, SyncGetHandle); // 3.0.1, 15/7/2008 - 13:55 {$endif} PostMessage( fImageEnView.Handle, IEM_PROGRESS, per, 0); end else fOnProgress(Sender, per); end; end; procedure TImageEnIO.DoFinishWork; begin fOnIntProgress(self, 100); // fOnIntProgress is always assigned if assigned(fOnFinishWork) then begin if assigned(fImageEnView) and (fImageEnView.Parent <> nil) and IsInsideAsyncThreads then begin // we are inside a thread, so send a message to the parent TImageEnView component, if exists {$ifdef IEHASTTHREADSTATICSYNCHRONIZE} if not fImageEnView.HandleAllocated then // 3.0.2, to avoid deadlocks TThread.Synchronize(nil, SyncGetHandle); // 3.0.1, 15/7/2008 - 13:55 {$endif} PostMessage( fImageEnView.Handle, IEM_FINISHWORK, 0, 0); end else fOnFinishWork(self); end; end; {!! TImageEnIO.LoadFromStreamPSD Declaration function LoadFromStreamPSD(Stream: TStream): Boolean; Description Loads an image from a stream containing an Adobe PSD file. The result will be false if an error is encountered, e.g. the file in the stream is not PSD format ( will be true). PSD files can contain multiple layers. To load separated layers: ImageEnView1.IO.Params.PSD_LoadLayers := True; ImageEnView1.IO.LoadFromStreamPSD(stream); To load only the merged/flattened image (default method): ImageEnView1.IO.Params.PSD_LoadLayers := False; ImageEnView1.IO.LoadFromStreamPSD(stream); !!} {$ifdef IEINCLUDEPSD} function TImageEnIO.LoadFromStreamPSD(Stream: TStream): Boolean; begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamPSD, Stream); Result := True; end else begin Result := SyncLoadFromStreamPSD(Stream); end; end; {$endif} {!! TImageEnIO.LoadFromFilePSD Declaration function LoadFromFilePSD(const FileName: WideString): Boolean; Description Loads an image from an Adobe PSD file. FileName is the file name including extension. Result will be false if the file is not PSD format (and will be false). Loading errors due to a file not being available will raise an exception. PSD files can contain multiple layers. To load separated layers: ImageEnView1.IO.Params.PSD_LoadLayers := True; ImageEnView1.IO.LoadFromFilePSD(filename); To load only the merged/flattened image (default method): ImageEnView1.IO.Params.PSD_LoadLayers := False; ImageEnView1.IO.LoadFromFilePSD(filename); Example ImageEnView1.IO.Params.PSD_LoadLayers := True; ImageEnView1.IO.LoadFromFilePSD('C:\input.psd'); !!} {$ifdef IEINCLUDEPSD} function TImageEnIO.LoadFromFilePSD(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFilePSD, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamPSD(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {$endif} {$ifdef IEINCLUDEPSD} function TImageEnIO.SyncLoadFromStreamPSD(Stream: TStream): Boolean; var Progress: TProgressRec; layers: TList; i, l: Integer; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; if Params.PSD_LoadLayers and Params.PSD_ReplaceLayers and assigned(fImageEnView) and (fImageEnView is TImageEnView) then // working with TImageEnView, remove all layers (fImageEnView as TImageEnView).LayersClear; fIEBitmap.RemoveAlphaChannel; layers := TList.Create; IEReadPSD(Stream, fIEBitmap, fParams, Progress, fParams.PSD_LoadLayers, layers); if Params.PSD_LoadLayers and assigned(fImageEnView) and (fImageEnView is TImageEnView) then begin // working with TImageEnView if layers.Count > 0 then begin if Params.PSD_ReplaceLayers then l := 0 else l := (fImageEnView as TImageEnView).LayersAddEx( ielkImage, 0, 0, -1, -1, TIEBitmap.Create(0, 0), False, False ); // create a transparent layer 0 when the first layer is moved with TIELayer(layers[0]) do if (PosX <> 0) or (PosY <> 0) then begin (fImageEnView as TImageEnView).Layers[l].SetDefaults; (fImageEnView as TImageEnView).Layers[l].Locked := True; (fImageEnView as TImageEnView).Layers[l].Bitmap.Allocate(fParams.Width, fParams.Height); (fImageEnView as TImageEnView).Layers[l].Bitmap.AlphaChannel.Fill(0); (fImageEnView as TImageEnView).LayersAddEx( ielkImage, 0, 0, -1, -1, TIEBitmap.Create(0, 0), False, False ); inc(l); end; for i := 0 to layers.Count - 1 do begin if i > 0 then l := (fImageEnView as TImageEnView).LayersAddEx( ielkImage, 0, 0, -1, -1, TIEBitmap.Create(0, 0), False, False ); if (fImageEnView as TImageEnView).LegacyBitmap then (fImageEnView as TImageEnView).Layers[l].Assign( TIELayer(layers[i]) ) // TIELayer.Swap is not possible when using LegacyBitmap (causes memory leak) else (fImageEnView as TImageEnView).Layers[l].Swap( TIELayer(layers[i]) ); end; end; end else if (layers.Count = 1) and not fParams.GetThumbnail then begin // One layer or TImageEnIO fIEBitmap.AlphaChannel.Assign( TIELayer(layers[0]).Bitmap.AlphaChannel ); if (fIEBitmap.Width <> fIEBitmap.AlphaChannel.Width) or (fIEBitmap.Height <> fIEBitmap.AlphaChannel.Height) then begin // an alpha channel can be moved and of different size fIEBitmap.AlphaChannel.Resize(fIEBitmap.AlphaChannel.Width+TIELayer(layers[0]).PosX, fIEBitmap.AlphaChannel.Height+TIELayer(layers[0]).PosY, 0, 0, iehRight, ievBottom); fIEBitmap.AlphaChannel.Resize(fIEBitmap.Width, fIEBitmap.Height, 0, 0, iehLeft, ievTop); end; end; for i := 0 to layers.count - 1 do TIELayer(layers[i]).Free(); layers.Free(); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioPSD; Update(); ResetModified( Params.PSD_LoadLayers ); finally DoFinishWork; Result := Not fAborting; end; end; {$endif} {$ifdef IEINCLUDEPSD} procedure TImageEnIO.SyncSaveToStreamPSD(Stream: TStream); var Progress: TProgressRec; merged, view: TImageEnView; layers: TList; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; if assigned(fImageEnView) and (fImageEnView is TImageEnView) then view := (fImageEnView as TImageEnView) else view := nil; if (view <> nil) then begin merged := TImageEnView.Create(nil); merged.LegacyBitmap := False; view.LayersDrawTo(merged.IEBitmap); merged.IEBitmap.Location := ieMemory; merged.IEBitmap.PixelFormat := view.Layers[0].Bitmap.PixelFormat; layers := view.LayersList; IEWritePSD(Stream, fParams, Progress, merged.IEBitmap, layers); merged.free; end else begin layers := TList.Create; IEWritePSD(Stream, fParams, Progress, fIEBitmap, layers); layers.free; end; finally DoFinishWork; end; end; {$endif} {!! TImageEnIO.SaveToStreamPSD Declaration procedure SaveToStreamPSD(Stream: TStream); Description Saves the current image to a stream in PSD format. PSD supports multiple layers, so it can store position and other useful info (like layer name). PSD also has a merged representation of the image to fast preview the merged result. Note: You can also save layers in IEN and SVG format !!} {$ifdef IEINCLUDEPSD} procedure TImageEnIO.SaveToStreamPSD(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamPSD, Stream); end else begin SyncSaveToStreamPSD(Stream); end; end; {$endif} {!! TImageEnIO.SaveToFilePSD Declaration procedure SaveToFilePSD(const FileName: WideString); Description Saves the current image or all layers to a file in PSD format. PSD supports multiple layers, so it can store position and other useful info (like layer name). PSD files also have a merged representation of the image to fast preview the merged result. FileName is the file name including extension. Notes: - If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. - You can also save layers in IEN and SVG format !!} {$ifdef IEINCLUDEPSD} procedure TImageEnIO.SaveToFilePSD(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFilePSD, FileName); exit; end; fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fParams.PSD_LargeDocumentFormat := IEFilenameInExtensions(string(FileName), '*.psb'); // automatically selec large document format for PSB fs := TIEWideFileStream.Create(FileName, fmCreate); SyncSaveToStreamPSD(fs); fParams.FileName := FileName; fParams.FileType := ioPSD; finally FreeAndNil(fs); end; end; {$endif} procedure TImageEnIO.SetPrintLogFile(v: String); begin if iegPrintLogFileName <> '' then CloseFile(iegPrintLogFile); iegPrintLogFileName := v; if v <> '' then begin AssignFile(iegPrintLogFile, iegPrintLogFileName); Rewrite(iegPrintLogFile); end; end; function TImageEnIO.GetParams: TIOParams; begin if assigned( fIEBitmap ) and fIEBitmap.ParamsEnabled then Result := fIEBitmap.Params else Result := fParams; end; function TImageEnIO.GetPrintLogFile: String; begin result := iegPrintLogFileName; end; {!! TImageEnIO.ReplaceStreamTIFF Declaration function ReplaceStreamTIFF(Stream: TStream): integer; Description Save the current image into the specified multi-page TIFF file, replacing the image at the index specified by .. Note: The Stream position must be at the beginning of the TIFF content. !!} function TImageEnIO.ReplaceStreamTIFF(Stream: TStream): integer; var lpos: int64; begin lpos := Stream.Position; TIFFDeleteImStream(Stream, fParams.TIFF_ImageIndex); Stream.Position := lpos; result := InsertToStreamTIFF(Stream); end; {$ifdef IEINCLUDEWIC} {!! TImageEnIO.LoadFromStreamHDP Declaration function LoadFromStreamHDP(Stream: TStream): Boolean; Description Loads an image from a stream containing a Microsoft HD Photo file. The result will be false if an error is encountered, e.g. the file in the stream is not HDP format ( will be true). Requires: Windows XP (SP2) with .Net 3.0, Windows Vista or newer. !!} function TImageEnIO.LoadFromStreamHDP(Stream: TStream): Boolean; begin if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC LOADING TIEIOThread.CreateLoadSaveStreamRetBool(self, LoadFromStreamHDP, Stream); Result := True; end else begin Result := SyncLoadFromStreamHDP(Stream); end; end; {!! TImageEnIO.LoadFromFileHDP Declaration function LoadFromFileHDP(const FileName: WideString): Boolean; Description Loads an image from a Microsoft HD Photo file. FileName is the file name including extension. Result will be false if the file is not HDP format (and will be false). Loading errors due to a file not being available will raise an exception. Requires: Windows XP (SP2) with .Net 3.0, Windows Vista or newer. !!} function TImageEnIO.LoadFromFileHDP(const FileName: WideString): Boolean; var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC LOADING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFileRetBool(self, LoadFromFileHDP, FileName); Result := True; exit; end; fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.create(FileName, fmOpenRead or fmShareDenyWrite); try Result := SyncLoadFromStreamHDP(fs); fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.SaveToStreamHDP Declaration procedure SaveToStreamHDP(Stream: TStream); Description Saves the current image to a stream in Microsoft HD Photo file format. Requires: Windows XP (SP2) with .Net 3.0, Windows Vista or newer. !!} procedure TImageEnIO.SaveToStreamHDP(Stream: TStream); begin CheckHaveValidBitmap(); if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin // ASYNC SAVING TIEIOThread.CreateLoadSaveStream(self, SaveToStreamHDP, Stream); end else begin SyncSaveToStreamHDP(Stream); end; end; {!! TImageEnIO.SaveToFileHDP Declaration procedure SaveToFileHDP(const FileName: WideString); Description Saves the current image to a file in Microsoft HD Photo format. FileName is the file name including extension. Note: If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. Requires: Windows XP (SP2) with .Net 3.0, Windows Vista or newer. !!} procedure TImageEnIO.SaveToFileHDP(const FileName: WideString); var fs: TIEWideFileStream; begin CheckHaveValidBitmap(); // ASYNC SAVING if (not fIEBitmapCreated) and fAsyncMode and (not IsInsideAsyncThreads) then begin TIEIOThread.CreateLoadSaveFile(self, SaveToFileHDP, FileName); exit; end; fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmCreate); SyncSaveToStreamHDP(fs); fParams.FileName := FileName; fParams.FileType := ioHDP; finally FreeAndNil(fs); end; end; function TImageEnIO.SyncLoadFromStreamHDP(Stream: TStream): Boolean; var Progress: TProgressRec; begin {$IFDEF IEForceVarInitialization} Result := False; {$ENDIF} try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; fParams.ResetInfo; fIEBitmap.RemoveAlphaChannel; IEHDPRead(Stream, fIEBitmap, fParams, Progress, false); CheckDPI; if fAutoAdjustDPI then AdjustDPI; fParams.FileName := ''; fParams.FileType := ioHDP; Update(); ResetModified(); finally DoFinishWork; Result := Not fAborting; end; end; procedure TImageEnIO.SyncSaveToStreamHDP(Stream: TStream); var Progress: TProgressRec; begin try fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); if not MakeConsistentBitmap([]) then exit; IEHDPWrite(Stream, fIEBitmap, fParams, Progress); finally DoFinishWork; end; end; {$endif} // HDP {$ifdef IEINCLUDERESOURCEEXTRACTOR} {!! TImageEnIO.LoadFromResource Declaration procedure LoadFromResource(const ModulePath: WideString; const ResourceType: String; const ResourceName: String; Format: TIOFileType); Description Loads the specified image resource from PE files like EXE, DLL, OCX, ICL, BPL, etc. Parameter Description ModulePath Specifies the path and filename of PE module. ResourceType Resource type as string (ie 'Bitmap', 'Cursor'). ResourceName Resource name as string (ie 'INTRESOURCE:100', 'Hand'). Format Specifies the expected file format. If Format is ioUnknown, then try to find the format automatically. ioUnknown should fail for BMP, ICO and CUR resources.
See also:
Example // Load resource 143, in "Bitmap"s, from "explorer.exe" (should be a small Windows logo) ImageEnView1.IO.LoadFromResource('explorer.exe', 'Bitmap', 'INTRESOURCE:143', ioBMP); !!} procedure TImageEnIO.LoadFromResource(const ModulePath: WideString; const ResourceType: String; const ResourceName: String; Format: TIOFileType); var re: TIEResourceExtractor; buffer: Pointer; bufferLen: Integer; begin re := TIEResourceExtractor.Create(ModulePath); try buffer := re.GetBuffer(AnsiString(ResourceType), AnsiString(ResourceName), bufferLen); fParams.IsResource := true; LoadFromBuffer(buffer, bufferLen, format); finally fParams.IsResource := false; re.Free; end; end; {$endif} // IEINCLUDERESOURCEEXTRACTOR {!! TImageEnIO.LoadFromFileIEN Declaration function LoadFromFileIEN(const FileName: WideString; Append: Boolean = False): Boolean; Description Loads an image from an ImageEn's native image format, which preserves the image and any layers. FileName is the file name including extension. Result will be false if the file is not ImageEn format (and will be true). Loading errors due to a file not being available will raise an exception. If Append is True, the existing content is not cleared, i.e. layers in this file will be added to existing layers. Notes: - If the TImageEnIO is attached to a TImageEnView then layers in the file will be loaded, if it is attached to a TIEBitmap or TBitmap then the file will be loaded as a merged image. - You can also load layers with the PSD format Example // Save current layer configuration (compress images as jpeg) ImageEnView1.IO.Params.IEN_Compression := ioJPEG; ImageEnView1.IO.SaveToFileIEN( 'D:\layers.ien' ); // Load saved layers ImageEnView1.IO.LoadFromFileIEN( 'D:\layers.ien' ); Example ImageEnView1.IO.LoadFromFileIEN('C:\input.dat'); See Also - - - - - !!} function TImageEnIO.LoadFromFileIEN(const FileName: WideString; Append: Boolean = False): Boolean; var fs: TIEWideFileStream; begin fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.create(FileName, fmOpenRead or fmShareDenyWrite); try Result := LoadFromStreamIEN( fs, Append ); if ( fParams.FileName = '' ) or ( Append = False ) then fParams.FileName := FileName; finally FreeAndNil(fs); end; end; {!! TImageEnIO.LoadFromStreamIEN Declaration function LoadFromStreamIEN(Stream: TStream; Append: Boolean = False): Boolean; Description Loads an image from a stream containing a file in ImageEn's native format, which preserves the image and any layers. The result will be false if an error is encountered, e.g. the file in the stream is not IEN format ( will be true). If Append is True, the existing content is not cleared, i.e. layers in this file will be added to existing layers. Note: If the TImageEnIO is attached to a TImageEnView then layers in the file will be loaded, if it is attached to a TIEBitmap or TBitmap then the file will be loaded as a merged image. Example // Save current layer configuration (compress images as jpeg) ImageEnView1.IO.Params.IEN_Compression := ioJPEG; ImageEnView1.IO.SaveToStreamIEN( Stream ); // Load saved layers ImageEnView1.IO.LoadFromStreamIEN( Stream ); See Also - - - - - !!} function TImageEnIO.LoadFromStreamIEN(Stream: TStream; Append: Boolean = False): Boolean; var basePos: Integer; getThumbnail: Boolean; tempIE : TImageEnView; begin fAborting := false; try basePos := Stream.Position; fParams.ResetInfo; getThumbnail := fParams.IEN_GetThumbnail; if getThumbnail then begin ParamsFromStreamIEN( Stream, True ); Result := ( fAborting = False ) and ( fIEBitmap.Width > 1 ); if result then begin fParams.FileName := ''; fParams.FileType := ioIEN; Update(); exit; end; Stream.Position := basePos; end; if ( getThumbnail = False ) and assigned( fImageEnView ) and ( fImageEnView is TImageEnView ) then fAborting := not (fImageEnView as TImageEnView).LayersLoadFromStream( Stream, Append, fOnIntProgress ) else begin // Get params ParamsFromStreamIEN( Stream, False ); Stream.Position := basePos; // TImageEnView not associated, render image to IEBitmap tempIE := TImageEnView.Create(nil); try tempIE.LegacyBitmap := False; fAborting := not tempIE.LayersLoadFromStream( Stream, False, fOnIntProgress ); tempIE.LayersMergeAll( True ); fIEBitmap.Assign( tempIE.IEBitmap ); Update(); finally tempIE.Free; end; end; fParams.FileName := ''; fParams.FileType := ioIEN; finally DoFinishWork; Result := not fAborting; if result then ResetModified( True ); end; end; {!! TImageEnIO.SaveToStreamIEN Declaration procedure SaveToStreamIEN(Stream: TStream); Description Saves the current image in the connected TImageEnView to a stream in ImageEn's native format, which preserves the image and any layers. Notes: - An exception will be raised if the TImageEnIO is not attached to a TImageEnView - If an internal save error is encountered will return true - cannot be ioTIFF. - You can also save layers in PSD and SVG format Example // Save current layer configuration (compress images as jpeg) ImageEnView1.IO.Params.IEN_Compression := ioJPEG; ImageEnView1.IO.SaveToStreamIEN( Stream ); // Load saved layers ImageEnView1.IO.LoadFromStreamIEN( Stream ); See Also - - - - - !!} procedure TImageEnIO.SaveToStreamIEN(Stream: TStream); begin if assigned( fImageEnView ) = false then raise EIEException.create( 'Must be attached to a TImageEnView to save in IEN format' ); try (fImageEnView as TImageEnView).LayersSaveToStream( Stream, fParams.IEN_Compression, False, False, True, fOnIntProgress ); fAborting := False; except fAborting := True; end; DoFinishWork(); end; {!! TImageEnIO.SaveToFileIEN Declaration procedure SaveToFileIEN(const FileName: WideString); Description Saves the current image in the connected TImageEnView to a file in ImageEn's native format, which preserves the image and any layers. FileName is the file name including extension. Notes: - An exception will be raised if the TImageEnIO is not attached to a TImageEnView - If an internal save error is encountered will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception. - cannot be ioTIFF. - You can also save layers in PSD and SVG format Example // Save current layer configuration (compress images as jpeg) ImageEnView1.IO.Params.IEN_Compression := ioJPEG; ImageEnView1.IO.SaveToFileIEN( 'D:\layers.ien' ); // Load saved layers ImageEnView1.IO.LoadFromFileIEN( 'D:\layers.ien' ); See Also - - - - - !!} procedure TImageEnIO.SaveToFileIEN(const FileName: WideString); var fs: TIEWideFileStream; begin if assigned( fImageEnView ) = false then raise EIEException.create( 'Must be attached to a TImageEnView to save in IEN format' ); fs := nil; try fAborting := true; // So that fAborting is True if the file is not found fs := TIEWideFileStream.Create(FileName, fmCreate); SaveToStreamIEN( fs ); fParams.FileName := FileName; fParams.FileType := ioIEN; finally FreeAndNil(fs); end; end; // Sets just IEN params // LoadThumbnail must be true at all times, except when we ONLY need to get the IO Params procedure TImageEnIO.ParamsFromStreamIEN(Stream: TStream; LoadThumbnail: Boolean = False); var recHead: TLayerHeader; headWidth, headHeight: Integer; headDesc: Widestring; begin fAborting := True; if IELayersLoadHeaderFromStream( Stream, recHead, headWidth, headHeight, headDesc, fIEBitmap, LoadThumbnail ) = False then exit; fParams.IEN_Compression := recHead.FileFormat; fParams.fIEN_LayerCount := recHead.LayersCount; fParams.fIEN_Version := recHead.Version; fParams.IEN_Description := ''; if recHead.Version >= 7000 then begin fParams.IEN_Description := headDesc; fParams.Width := headWidth; fParams.Height := headHeight; fParams.OriginalWidth := headWidth; fParams.OriginalHeight := headHeight; end; fParams.FileType := ioIEN; fAborting := False; end; {!! TImageEnIO.SaveToStreamSVG Declaration procedure SaveToStreamSVG(Stream: TStream); Description Saves the current image to a stream in Scalable Vector Graphics format. SVG is a vector format that can be displayed be web browsers. If the TImageEnIO is connected to an TImageEnView, then each of the will be output as a scalable object. If connected to a TImageEnVect, the objects will be converted to layers and then output. Otherwise the is output as SVG with an embedded raster image. SVG Exporting Limitations: - Gradient fills are not supported at this time - Mask layers are not supported - Some shapes of a TIEShapeLayer (those not listed in ) will need to rasterized as an image (i.e. will no longer be vectors) Notes: - sets the image format for embedded raster images. It should be a web-safe format such as ioPNG or ioJPEG - If an internal save error is encountered will return true (e.g. there are no valid layers) - You can also save layers in IEN and PSD format - SVG is an export only format. ImageEn does not support loading of SVG files Example // Save current layers (compress image layers as jpeg) ImageEnView1.IO.Params.SVG_ImageCompression := ioJPEG; ImageEnView1.IO.SaveToStreamSVG( Stream ); See Also - - !!} procedure TImageEnIO.SaveToStreamSVG(Stream: TStream); var Progress: TProgressRec; begin fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); WriteSVGFileOrStream( '', Stream, AttachedImageEn, IEBitmap, Params.SVG_ImageCompression, Progress ); DoFinishWork(); end; {!! TImageEnIO.SaveToFileSVG Declaration procedure SaveToFileSVG(const FileName: WideString); Description Saves the current image to a file in Scalable Vector Graphics format. SVG is a vector format that can be displayed be web browsers. If the TImageEnIO is connected to an TImageEnView, then each of the will be output as a scalable object. If connected to a TImageEnVect, the objects will be converted to layers and then output. Otherwise the is output as SVG with an embedded raster image. FileName is the file name including extension. SVG Exporting Limitations: - Gradient fills are not supported at this time - Mask layers are not supported - Some shapes of a TIEShapeLayer (those not listed in ) will need to rasterized as an image (i.e. will no longer be vectors) Notes: - If an internal save error is encountered will return true (e.g. there are no valid layers). Saving issues due to insufficient write permissions and disk write failures will raise an exception. - Embedded images will be saved in the format specified by . - You can also save layers in IEN and PSD format - SVG is an export only format. ImageEn does not support loading of SVG files Demo Demos\ImageEditing\Layers_AllTypes\Layers.dpr Example // Save current layers (compress image layers as jpeg) ImageEnView1.IO.Params.SVG_ImageCompression := ioJPEG; ImageEnView1.IO.Params.JPEG_Quality := 80; ImageEnView1.IO.SaveToFileSVG( 'D:\layers.SVG' ); See Also - - !!} procedure TImageEnIO.SaveToFileSVG(const FileName: WideString); var Progress: TProgressRec; begin fAborting := false; Progress := ProgressRec( Self, fOnIntProgress, fAborting ); WriteSVGFileOrStream( FileName, nil, AttachedImageEn, IEBitmap, Params.SVG_ImageCompression, Progress ); fParams.FileName := FileName; fParams.FileType := ioSVG; DoFinishWork(); end; {!! TImageEnIO.Seek Declaration function Seek(Page : ; FileName : WideString = ''): Integer; Description Load the specified page from the last loaded multipage file, including TIFF, GIF, AVI and other video types. This method uses to load the file (hence the file name must be provided), unless it is part of or where LoadPicture is called instead. Parameter Description Page Page to load. FileName Optional file name. If empty will use the last loaded file name.
Returns the loaded page index. Example // load first page ImageEnView1.IO.Seek(ieioSeekFirst, 'multipage.tiff'); // load next page ImageEnView1.IO.Seek(ieioSeekNext); !!} function TImageEnIO.Seek(Destination: TIEIOSeekDestination; FileName: WideString = ''): Integer; var fn: WideString; begin result := 0; case Destination of ieioSeekFirst: result := 0; ieioSeekPrior: result := imax(0, fParams.ImageIndex - 1); ieioSeekNext: result := imin(fParams.ImageCount - 1, fParams.ImageIndex + 1); ieioSeekLast: result := fParams.ImageCount - 1; end; if FileName = '' then fn := fParams.FileName else fn := FileName; {$ifdef IESUPPORTINTERFACESUPPORT} if assigned(fImageEnView) and Supports(fImageEnView, IIELoadPicture) then begin fParams.ImageIndex := result; (fImageEnView as IIELoadPicture).LoadPicture(); end else {$endif} begin if (FileName = '') and (result = fParams.ImageIndex) then exit; // nothing to load fParams.ImageIndex := result; LoadFromFile(fn); end; end; {$ifdef IEIncludeDeprecatedInV6} // Deprecated in 6.2.0 (2015-06-08) function TImageEnIO.GetProxyAddress: WideString; begin Result := IEGlobalSettings().ProxyAddress; end; function TImageEnIO.GetProxyUser: WideString; begin Result := IEGlobalSettings().ProxyUser; end; function TImageEnIO.GetProxyPassword: WideString; begin Result := IEGlobalSettings().ProxyPassword; end; procedure TImageEnIO.SetProxyAddress(Value: WideString); begin IEGlobalSettings().ProxyAddress := Value; end; procedure TImageEnIO.SetProxyUser(Value: WideString); begin IEGlobalSettings().ProxyUser := Value; end; procedure TImageEnIO.SetProxyPassword(Value: WideString); begin IEGlobalSettings().ProxyPassword := Value; end; {$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// procedure IEInitialize_imageenio; begin // end; procedure IEFinalize_imageenio; begin // end; end.