Acquiring ImagesΒΆ
The simplest way to implement image acquisition with Q2Pix is something like this:
C_TEXT($sourceID) $sourceID:=ImgDlog_SelectSource If ($sourceID#"") C_TEXT($imgPath) $imgPath:=ImgSource_AcquireImage ($sourceID) If ($imgPath#"") // ... // Work with the acquired image End if End if
The source device is selected with the ImgDlog_SelectSource
call,
which presents the source selection dialog:
The acquired image is saved in the system’s temporary directory (the default).
To save the image in an existing folder named "Scans"
inside the "Resources"
folder,
the folder path can be specified in the options passed to ImgSource_AcquireImage
:
C_TEXT($sourceID) $sourceID:=ImgDlog_SelectSource If ($sourceID#"") C_TEXT($destDirPath) $destDirPath:=Get 4D folder(Current resources folder)+"Scans"+Folder separator $destDirPath:=Convert path system to POSIX($destDirPath) C_OBJECT($options) OB SET($options;"Directory";$destDirPath) C_TEXT($imgPath) $imgPath:=ImgSource_AcquireImage ($sourceID;$options) If ($imgPath#"") // ... // Work with the acquired image End if End if
The following example shows how to acquire multiple images from a suitable source and assemble those into a multi-frame TIFF:
C_TEXT($sourceID) $sourceID:=ImgDlog_SelectSource If ($sourceID#"") C_OBJECT($options) OB SET($options;"Multiple";True) C_OBJECT($result) $result:=ImgSource_Acquire ($sourceID;$options) If (OB Is defined($result)) ARRAY TEXT($imagePaths;0) OB GET ARRAY($result;"Images";$imagePaths) C_LONGINT($imageCount) $imageCount:=Size of array($imagePaths) If ($imageCount>0) C_TEXT($destDirPath) $destDirPath:=Get 4D folder(Current resources folder)+"Scans"+Folder separator If (Test path name($destDirPath)#Is a folder) CREATE FOLDER($destDirPath;*) End if C_TEXT($tiffPath) $tiffPath:=$destDirPath+"MultiframeImage.tiff" $tiffPath:=Convert path system to POSIX($tiffPath) C_TEXT($tiffDocRef) $tiffDocRef:=ImgDoc_CreateNew If ($tiffDocRef#"") C_LONGINT($success) $success:=1 C_LONGINT($imageIdx) For ($imageIdx;1;$imageCount) C_TEXT($srcDocRef) $srcDocRef:=ImgDoc_CreateWithFile ($imagePaths{$imageIdx}) If ($srcDocRef#"") ImgDoc_InsertFrame ($tiffDocRef;$imageIdx;$srcDocRef;1) ImgObj_Release ($srcDocRef) Else ALERT("Image could not be loaded: "+$imagePaths{$imageIdx}) $success:=0 $imageIdx:=$imageCount+1 End if End for If ($success=1) $success:=ImgDoc_SaveInFile ($tiffDocRef;$tiffPath) If ($success#1) ALERT("Failed to save multi-frame TIFF file:"+$tiffPath) End if End if ImgObj_Release ($tiffDocRef) End if // Delete temporary files For ($imageIdx;1;$imageCount) DELETE DOCUMENT(Convert path POSIX to system($imagePaths{$imageIdx})) End for End if End if End if