Zooming on an image.

Zooming on an image.

Postby HunterEC » Thu Aug 25, 2016 7:05 pm

Guys:

Is there a way to zoom an image incrementally ? The following code zoom the image too big:
Code: Select all  Expand view
  WITH OBJECT oImg
      if :lStretch
         :lStretch   := .f.
         :Zoom( 1 )
         ...
 


Thank you very much !
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Zooming on an image.

Postby ukoenig » Fri Aug 26, 2016 7:57 am

I had the same problem and needed a solution for folder-display and printing
Do You need them both preview and print ?

Image

calculated printingsize and position of a defined area

Image

regards
Uwe :?:
Last edited by ukoenig on Fri Aug 26, 2016 4:08 pm, edited 2 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Zooming on an image.

Postby HunterEC » Fri Aug 26, 2016 8:17 am

Uwe:

My friend. yes, I need both, preview & print. Thank you very much !!!
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Zooming on an image.

Postby ukoenig » Fri Aug 26, 2016 9:33 am

Gustavo,

I think everything You may need is included.
Just let me know in case of something is still missing

The 1. Part the folder-preview

Image

Code: Select all  Expand view

STATIC oFld, oPlan

// -------------

// cImage = Imagename

REDEFINE FOLDEREX oFld ID 120 PROMPT "&Patient", "&Ka./ Pfl.", "&Arzt / Re.-an / Bem.", "Plan";
BITMAPS c_Pfad1 + "Eingabe.bmp", c_Pfad1 + "Eingabe.bmp", c_Pfad1 + "Eingabe.bmp", c_Pfad1 + "Eingabe.bmp" ;
DIALOGS "Patient1", "Patient2", "Patient3", "Patient4" ROUND 5 ;
ON CHANGE ( nPage := oFld:nOption, ;
            IIF( nPage = 4, ( IMG_PADJ( oPlan, c_Path, TRIM(cImage) ), oPlan:Refresh() ), NIL ), ;
            oFld:aDialogs[ nPage ]:Update() )

// ----Folderpage 4 ( Image ) --------

REDEFINE IMAGE oPlan ID 110 FILENAME c_Path + TRIM(cImage) OF oFld:aDialogs[ 4 ] PIXEL BORDER
oPlan:LoadImage( , c_Path + TRIM(cImage) )

// ------------------- IMAGE ADJUSTMENT ( keep aspect ratio ) PREVIEW ------------

FUNCTION IMG_PADJ( oDrawImg, cPath, cImage )
LOCAL nImgWidth, nImgHeight, nPWidth, nWFactor, nHFactor
LOCAL aRect := GETCLIENTRECT( oDrawImg:hWnd )  // Get RESOURCE-size !!!

oDrawImg:LOADIMAGE( , cPath + cImage )  // Image

nPWidth := aRect[4]                     // Default Resource-Image-Width
nPHeight := aRect[3]                        // Default Resource-Image-Height

nImgWidth := oDrawImg:nWidth                // Image-Width
nImgHeight := oDrawImg:nHeight          // Image-Height

nWFactor := aRect[4] / nImgWidth            // Width / Image-Width
nHFactor := aRect[3] / nImgHeight           // Height / Image-Height

IF nWFactor > 1 .and. nHFactor > 1          // Dlg-Width > ImageWidth und Dlg-Height > Image-Height
    IF nWFactor < nHFactor              // Width-factor > Height-factor  
        nPHeight := nImgHeight * nWFactor
    ELSE                            // Width-factor < Height-factor  
        nPWidth := nImgWidth * nHFactor
    ENDIF
ELSEIF nWFactor < 1 .and. nHFactor < 1      // Dlg-Width < Image-Width und Dlg-Height < Image-Height
    IF nWFactor < nHFactor              // Width-factor > Height-factor  
        nPHeight := nImgHeight * nWFactor
    ELSE                            // Width-factor < Height-factor  
        nPWidth := nImgWidth * nHFactor
    ENDIF
ELSEIF nWFactor < 1 .and. nHFactor > 1      // Dlg-Width < Image-Width und Dlg-Height > Image-Height
    nPHeight := nImgHeight * nWFactor  
ELSEIF nWFactor > 1 .and. nHFactor < 1      // Dlg-Width > Image-Width und Dlg-Height < Image-Height
    nPWidth := nImgWidth * nHFactor      
ENDIF
hResizeImg := ResizeImg( oDrawImg:hBitmap, nPWidth, nPHeight )  // Resize Image
oDrawImg:hBitmap := hResizeImg

oDrawImg:Refresh()
oDlg:Refresh()

RETURN( NIL )
 


The 2. Part Printing

Image

Code: Select all  Expand view


// ------------------

FUNCTION P_DRUCK( oDlg, nTyp )

IF nTyp = 1
    MSGMETER( { | oMeter, oText, oDlg, lEnd | ;
             P_REPORT1( oMeter, oText, oDlg, @lEnd ) }, "Fortschritt...", ;
             "Erzeuge Leistungsliste ..." )
ENDIF

RETURN( NIL )

// -------------

FUNCTION P_REPORT1( oMeter, oText, oDlg )
LOCAL nGesamt := 0, aDatP[55], oImage, aPoint, nImgSize := 1300
LOCAL oPRINT, oFont1, oFont2, oPen1, oPen2, nRechngNr
LOCAL nLinI, nColI, nLinF, nColF, aDValue[30], nLstgSumme := 0, I := 1
LOCAL nMargin, nIWidth, nIHeight, nColWidth, aText[ 2 ], nImgLeft := 1
LOCAL nWFactor, nHFactor, nPWidth, nPHeight, nRow, nCol  

DBSELECTAREA( "PATIENT" )
( "PATIENT" )->(DBGOTOP())

//oMeter:nTotal = nMenge

PRINTER oPRINT ; // FROM USER  ;
PREVIEW  MODAL ;
NAME "Patientenliste drucken"

IF EMPTY( oPRINT:hDC )
      MsgStop ( "Drucker nicht bereit !" )
      RETURN(.f.)
ENDIF
IF aVal[180] = 2    //fix for report thumbnails
    TPreview():lListViewHide := .T.
ENDIF

DEFINE FONT oFont1 NAME "Arial" SIZE 0, -10 OF oPRINT
DEFINE FONT oFont2 NAME "Arial" SIZE 0, -12 OF oPRINT
DEFINE FONT oFont3 NAME "Arial" SIZE 0, -14 BOLD OF oPRINT

DEFINE PEN oPen1 WIDTH  aVal[201] * 4 OF oPRINT
DEFINE PEN oPen2 WIDTH  aVal[202] * 4  OF oPRINT
 
oPRINT:SetPage(9)       //  A4
oPRINT:SetPortrait()        //  Vertical

nMargin     := Int( 0.12 * oPRINT:nHorzRes() )
nWidth      := 8.2 * nMargin
nColWidth := Int( ( nWidth - ( nMargin / 2 ) ) )  
nImgLeft    := nMargin

nSeite := 0
DO WHILE !EOF()
     aDatP[31]   := ("PATIENT")->DMERKER // selected record

     IF aDatP[31] = "X" // record selected
          aDatP[47]   := TRIM( ("PATIENT")->ORTSPLAN ) // Image-name

          PAGE
          ....
          ....
         // ------------- SECTION IMAGE PRINT -----------------
           
         // position and zoom related to defined left margin
         // aVal[177]    := ("SYSTEM")->IMAGE_TOP   // Default factor = 1, nTop = 1150
         // aVal[178]    := ("SYSTEM")->IMAGE_LEFT // Default factor = 1, nMargin
         // aVal[179]    := ("SYSTEM")->IMAGe_ZOOM // Default factor = 1, can be used for small images

         IF aVal[178] > 0
              nImgLeft := nMargin * aVal[178]
              IF nImgLeft > nMargin
                   nImgSize := nImgSize - ( nImgLeft - nMargin )
              ENDIF
         ENDIF
         //                                    nDlgWidth, nDlgHeight, Path,       Image
         aImgSize := PRINT_IMG( nImgSize,  1000,         c_Pfad5, aDatP[47] )
         IF aVal[179] > 0
              aImgSize[1] := aImgSize[1] * aVal[179]
              aImgSize[2] := aImgSize[2] * aVal[179]
         ENDIF      
         // PrintImage( nRow, nCol, uImage,   image-name,     nWidth,   nHeight,   lStretch, nAlpha, lTransp, lGray )
         oPRINT:PrintImage( 1150 * aVal[177], nImgLeft, c_Pfad5 + aDatP[47], aImgSize[1], aImgSize[2], .T.)

         / -------------

         nSeite++
         oPRINT:cmSay( 28.2, 17.5, "Page : " + LTRIM(STR(nSeite)), oFont2,,CLR_BLACK,,PAD_LEFT  )

         ENDPAGE
     ENDIF
     ("PATIENT")->(DBSKIP(+1))

ENDDO

ENDPRINT

oFont1:End()
oFont2:End()
oFont3:End()

oPen1:End()
oPen2:End()

DBSELECTAREA( "PATIENT" )
("PATIENT")->(DBGOTOP())

RETURN( NIL )

// ------------------- IMAGE - ADJUSTMENT ( keep asprct ration ) PRINTING -----

FUNCTION PRINT_IMG( nDlgWidth, nDlgHeight, cPath, cImage )
LOCAL nIWidth, nIHeight, nPWidth, oDrawImg, aImgSize[2]

DEFINE IMAGE oDrawImg FILE cPath + cImage

nIWidth := oDrawImg:nWidth
nIHeight := oDrawImg:nHeight

nWFactor := nDlgWidth / nIWidth         // Width / Image-Width
nHFactor := nDlgHeight / nIHeight           // Höhe / Image-Height
nPWidth := nDlgWidth
nPHeight := nDlgHeight  
IF nWFactor > 1 .and. nHFactor > 1          // Dlg-Width > Image-Width und Dlg-Height > Image-Height
    IF nWFactor < nHFactor              // Width-factor > Height-factor  
        nPHeight := nIHeight * nWFactor
    ELSE                            // Width-factor < Height-factor  
        nPWidth := nIWidth * nHFactor
    ENDIF
ELSEIF nWFactor < 1 .and. nHFactor < 1      // Dlg-Width < Image-Width und Dlg-Height < Image-Height
    IF nWFactor < nHFactor              // Width-factor > Height-factor  
        nPHeight := nIHeight * nWFactor
    ELSE                            // Width-factor < Height-factor  
        nPWidth := nIWidth * nHFactor
    ENDIF
ELSEIF nWFactor < 1 .and. nHFactor > 1      // Dlg-Width < Image-Width und Dlg-Height > Image-Height
    nPHeight := nIHeight * nWFactor  
ELSEIF nWFactor > 1 .and. nHFactor < 1      // Dlg-Width > Image-Width und Dlg-Height < Image-Height
    nPWidth := nIWidth * nHFactor      
ENDIF
oDrawImg:End()

aImgSize[1] := nPWidth
aImgSize[2] := nPHeight

RETURN( aImgSize )
 


regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests