Page 1 of 1

simple image viewer - sample

Posted: Fri Jun 09, 2023 6:27 am
by Otto
Dear João,
Thank you, João Santos, for this beautiful example. I am reposting it as a standalone post to ensure it doesn't get overlooked.
I have made an effort to create a description of it using ChatGPT.
Best regards,
Otto

Image

Description:
This program appears to be written in Harbour, a language that is a modern, open-source variant of the older Clipper language. The program uses the FiveWin library, which is a popular library for creating GUI applications in Harbour.

Let's break down what the program does:

1. **Includes**: It starts by including two header files, "FiveWin.ch" and "Image.ch". These likely provide additional functionality or definitions used in the program.

2. **Main Function**: The `Main()` function is the entry point of the program. Here, it initializes several local variables, sets some properties, and defines the GUI of the program.

3. **Dialog Definition**: It defines a dialog box (`oDlg`) with various properties, including title, color, and font. The dialog does not have a help icon.

4. **Image Display**: An image (`oImage`) is displayed in the dialog box. The image can be scrolled, and its progress bar is turned off by default.

5. **Buttons**: The program defines several buttons with different actions:
- "Select Image": This button calls the `GetImage()` function to allow the user to select an image file to display.
- "Print": This button calls the `PrintImage()` function to print the currently displayed image.
- "Copy": This button copies the currently displayed image to the clipboard.
- "Paste": This button loads an image from the clipboard and refreshes the image display.
- "Save": This button saves the currently displayed image as "SAVED.JPG" and displays a message "saved as saved.jpg".
- "Exit": This button ends the dialog.

6. **Checkboxes**: There are two checkboxes that allow the user to adjust the image display:
- "Stretch": This checkbox allows the user to toggle whether the image should be stretched to fit the display area.
- "Set Alpha Channel": This checkbox allows the user to toggle the alpha channel of the image. However, the `SetAlpha()` function is not defined in the provided code.

7. **GetImage Function**: This function allows the user to select an image file of various formats (bmp, dib, pcx, jpg, gif, tga, rle) to display. The chosen image is then loaded into the image display.

8. **PrintImage Function**: This function prints the currently displayed image. It sets up a print job with the name "Image Printing", sets the page format and orientation, and prints the image.

In summary, the program is a simple image viewer that allows the user to select, display, print, copy, paste, and save images. It also provides options to stretch the image and adjust the alpha channel. However, note that some functionality such as `SetAlpha()` is not defined within the provided code.

ChatGPT

Code: Select all | Expand



    // C:\FWH..\SAMPLES\PRNIMAG1.PRG

    #include "FiveWin.ch"
    #include "Image.ch"

    FUNCTION Main()

       LOCAL oDlg, oImage, lSetAlpha := .T., cTitle, oFont

       // SetAlpha( .f. )

       SkinButtons()

       cTitle := FWDESCRIPTION + ": .JPG, .JIF, .GIF, .BMP, .DIB, .RLE, .TGA, .PNG."

       DEFINE FONT oFont  NAME "Ms Sans Serif"  SIZE 00, -12 BOLD

       DEFINE DIALOG oDlg FROM 0, 0 TO 22, 60 TITLE cTitle ;
          COLORS CLR_BLACK, CLR_WHITE TRANSPARENT FONT oFont

       oDlg:lHelpIcon := .F.

       @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg SCROLL // ADJUST

       oImage:Progress( .F. )

       @ 1, 28 BUTTON "Select Image" SIZE 50, 10  ;
          OF oDlg ACTION GetImage( oImage )

       @ 2, 28 BUTTON "Print" SIZE 50, 10 OF oDlg ;
          ACTION PrintImage( oImage )

       @ 3, 28 BUTTON "Copy" SIZE 50, 10 OF oDlg  ;
          ACTION oImage:CopyToClipboard()

       @ 4, 28 BUTTON "Paste" SIZE 50, 10 OF oDlg ;
          ACTION ( oImage:LoadFromClipboard(), oImage:Refresh() )

       @ 5, 28 BUTTON "Save" SIZE 50, 10 OF oDlg  ;
          ACTION ( oImage:SaveImage( "SAVED.JPG", 2, 25 ), ;
                   MsgInfo( "saved as saved.jpg" ) )

       @ 6, 28 BUTTON "Exit" SIZE 50, 10 OF oDlg ACTION( oDlg:End() ) CANCEL

       @ 10, 23 CHECKBOX oImage:lStretch PROMPT "Stretch" SIZE 50, 10 OF oDlg ;
          ON CHANGE ( oImage:ScrollAdjust(), oImage:Refresh() )

       @ 11, 23 CHECKBOX lSetAlpha PROMPT "Set Alpha Channel" SIZE 90, 10 OF oDlg ;
          ON CHANGE ( SetAlpha( lSetAlpha ), oImage:Refresh() )

       ACTIVATE DIALOG oDlg CENTERED

       oFont:End()

    RETURN NIL

    FUNCTION GetImage( oImage )

       LOCAL gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                                  "DIB   (*.dib)| *.dib|" +         ;
                                  "PCX   (*.pcx)| *.pcx|" +         ;
                                  "JPEG  (*.jpg)| *.jpg|" +         ;
                                  "GIF   (*.gif)| *.gif|" +         ;
                                  "TARGA (*.tga)| *.tga|" +         ;
                                  "RLE   (*.rle)| *.rle|" +         ;
                                  "All Files (*.*)| *.*"            ;
                                , "Please select a image file", 4 )

       IF .NOT. EMPTY( gcFile ) .AND. File( gcFile )

          oImage:LoadBmp( gcFile )

       ENDIF

    RETURN NIL

    FUNCTION PrintImage( oImage )

       LOCAL oPrn, nRow := 1.00
       LOCAL nLinLogo := 1.00, nColLogo := 600, nLargLogo := 650, nAltLogo := 650

       PRINT oPrn NAME "Image Printing" PREVIEW MODAL

       oPrn:SetPage(9)
       oPrn:SetPortrait()

       PAGE

          /*
          oPrn:PrintImage( 50, 50, oImage )
          */

          /*
          // oPrn:SayImage( nLinLogo, nColLogo, "LOGO.JPG", nLargLogo, nAltLogo )
          */

          @  nLinLogo, nColLogo PRINT TO oPrn IMAGE oImage SIZE nLargLogo, nAltLogo LASTROW nRow

       ENDPAGE

       ENDPRINT

    RETURN NIL

    // FIN / END
     

 

Re: simple image viewer - sample

Posted: Fri Jun 09, 2023 2:01 pm
by karinha
Dear Otto, very, very good indeed. Excellent definition. Congratulations.

Estimado Otto, muy, muy bien de hecho. Excelente definición. Parabiéns.

Origin / Origen:

https://forums.fivetechsupport.com/view ... bb413d24b9

Regards, saludos.

Re: simple image viewer - sample

Posted: Fri Jun 09, 2023 2:10 pm
by karinha
Another example / Otro ejemplo:

Code: Select all | Expand

// C:\FWH..\SAMPLES\PRNIMAG2.PRG by Mister Nages.

#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL oPrn

   PRINT oPrn PREVIEW

   PAGE

   @ 1,1 PRINT TO oPrn IMAGE ;
         "c:\fwh\bitmaps\olga1.jpg" ;
         SIZE 3,4 INCHES

   @ 5.3,1 PRINT TO oPrn IMAGE ;
         "https://www.jesmondfruitbarn.com.au/wp-content/uploads/2016/10/Jesmond-Fruit-Barn-Oranges.jpg" ;
         SIZE 4,4 INCHES

   ENDPAGE

   ENDPRINT

RETURN NIL

// FIN / END
 
Regards, saludos.

Re: simple image viewer - sample

Posted: Sat Jun 10, 2023 5:20 pm
by Silvio.Falconi
Another sample....My procedure for attaching documents to a product, a customer, a supplier to an invoice, etc


Image

Notice.. each type of document can be opened with specific application , my procedure search these application on computer
I can acquire a document with scanner and save directly on this produre