/* Convert image formats with xPrint
   -------------------------------*/
   
{ xPrint.i }

DEF STREAM O.
DEF VAR F           AS CHAR NO-UNDO.
DEF VAR sourceImage AS CHAR NO-UNDO.
DEF VAR targetImage AS CHAR NO-UNDO.
DEF VAR OK          AS LOGICAL NO-UNDO.
DEF VAR	imageWidth	AS INTEGER NO-UNDO.
DEF VAR	imageHeight	AS INTEGER NO-UNDO.

sourceImage = "C:\Temp\myImage.bmp".
targetImage = "C:\Temp\MyImage.jpg".


/*	For demo, get the file names
	===========================*/
SYSTEM-DIALOG GET-FILE sourceImage
    FILTERS "Bmp files (*.bmp)" "*.bmp",
            "JPG files (*.jpg)" "*.jpg",
            "TGA files (*.tga)" "*.tga",
            "WMF files (*.wmf)" "*.wmf",
            "EMF files (*.emf)" "*.emf",
            "PNG files (*.png)" "*.png"           
    DEFAULT-EXTENSION "*.bmp"
            MUST-EXIST
            USE-FILENAME
            TITLE "Enter source file name."
            UPDATE OK.
IF NOT OK THEN
                RETURN.

SYSTEM-DIALOG GET-FILE targetImage
            USE-FILENAME
    FILTERS "Bmp files (*.bmp)" "*.bmp",
            "JPG files (*.jpg)" "*.jpg",
            "TGA files (*.tga)" "*.tga",
            "WMF files (*.wmf)" "*.wmf",
            "EMF files (*.emf)" "*.emf",
            "PNG files (*.png)" "*.png"
    DEFAULT-EXTENSION "*.jpg"
            TITLE "Enter target file name."
            UPDATE OK.
IF NOT OK THEN
                RETURN.

/*	Proceed
	=====*/

        /* get the original image size
           -------------------------*/
RUN getImageDim(sourceImage,
            INPUT-OUTPUT imageWidth,
            INPUT-OUTPUT imageHeight).

F = SESSION:TEMP-DIRECTORY + "ImageFormat.xpr".
OUTPUT STREAM O TO VALUE(F).
PUT STREAM O CONTROL
        "<PRINT=NO><#1><UNITS=MM>"
        "<AT=+280,+200><IMAGE#1=" sourceImage ">"
        "<EXPORT=" targetImage ",WIDTH=" imageWidth ">".
OUTPUT STREAM O CLOSE.
RUN printFile( F ).

/* The created file is xxxxx0001.suffix 
   ----------------------------------*/
F = ENTRY(1, targetImage, '.') + "0001." + ENTRY(2, targetImage, ".").

OS-COPY VALUE(F) VALUE(targetImage).
OS-DELETE VALUE(F).
OS-DELETE VALUE( SESSION:TEMP-DIRECTORY + "ImageFormat.xpr" ).

      

