Tech Tip: Exporting picture field formats on disk
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: December 16, 2016
In v16, the command GET PICTURE FORMATS can take a peek of a picture that may contain multiple formats. If a database contains pictures, the following utlity method can evaluate a picture field and export all picture types on disk:
// -------------------------------------------------------------------------------- // Name: EXPORT_PICT_FLD_FORMATS_ON_DISK // Description: Method will search in a Picture Field record to determine if there // are multiple picture formats and will export to disk. // Input: // $1 (POINTER) - Pointer to the Picture field to search // $2 (TEXT) - Location to save the folder to save the files to // -------------------------------------------------------------------------------- C_POINTER($1;$fieldPtr;$tablePtr;$refFieldPtr) C_TEXT($2;$loc;$refFieldID) C_PICTURE($picture) C_LONGINT($i;$j) ARRAY TEXT(arrPics;0) If (Count parameters=2) $fieldPtr:=$1 $loc:=$2 $tablePtr:=Table(Table($fieldPtr)) // Extracting the Table from the field $refFieldPtr:=Field(Table($fieldPtr);1) // Assuming the first field is ID or Text type For ($i;1;Records in selection($tablePtr->)) GET PICTURE FORMATS($fieldPtr->;arrPics) $refFieldID:=String($refFieldPtr->) // Export the pictures to a location If (Size of array(arrPics)>1) // Assuming it is a PICT file If (Test path name($loc+String($refFieldPtr->))#Is a folder) CREATE FOLDER($loc+$refFieldID) For ($j;1;Size of array(arrPics)) $picture:=$fieldPtr-> If (arrPics{$j}#".pict") CONVERT PICTURE($picture;arrPics{$j}) WRITE PICTURE FILE($loc+$refFieldID+Folder separator+$refFieldID+arrPics{$j};$picture) End if CLEAR VARIABLE($picture) End For End if End if NEXT RECORD($tablePtr->) End for End if |
Here is an example of a picture field record that contains multiple formats:
Using the method to the record and extract all the picture formats to disk:
C_Text($loc) QUERY([Table_1];[Table_1]ID=4) $loc:=get 4d folder(Current resources folder) EXPORT_PICT_FLD_FORMATS_ON_DISK (->[Table_1]Field_3;$loc) |
Result creates pictures on disk with the field ID number as the folder name and file name:
See Also: