simple image viewer - sample

simple image viewer - sample

Postby Otto » Fri Jun 09, 2023 6:27 am

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 view  RUN



    // 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
     

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6364
Joined: Fri Oct 07, 2005 7:07 pm

Re: simple image viewer - sample

Postby karinha » Fri Jun 09, 2023 2:01 pm

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/viewtopic.php?f=3&t=43295&sid=fe6c663cbbfc32d427290cbb413d24b9

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: simple image viewer - sample

Postby karinha » Fri Jun 09, 2023 2:10 pm

Another example / Otro ejemplo:

Code: Select all  Expand view  RUN

// 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7872
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: simple image viewer - sample

Postby Silvio.Falconi » Sat Jun 10, 2023 5:20 pm

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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7090
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 61 guests