Zoom in on Picture - Uwe

Zoom in on Picture - Uwe

Postby Rick Lipkin » Fri Jun 29, 2012 12:52 pm

Uwe

I am starting an inventory module and one of the requests is to be able to show a picture of the part. I have no problem with incorporating a picture into a form. Do you know of a way with FreeImage to be able to doubleClick on the picture ( jpg or bmp ) to be able to enlarge the photo or to zoom out to increase the size of the picture ?

Many Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Zoom in on Picture - Uwe

Postby ukoenig » Fri Jun 29, 2012 2:17 pm

Rick,

The < Image-click-solution >

Code: Select all  Expand view

//------------- IMAGE -----------
FUNCTION START_IMAGE()
LOCAL oBmp

// Screen-adjust
// PUBLIC nSWidth := GetSysMetrics(0), nSHeight := GetSysMetrics(1)

IF FILE( cWorkFile ) // Image exists ?
    @ 5, 5 IMAGE oBmp FILENAME cWorkFile  OF oWnd ;
    SIZE nSWidth - 30, nSHeight - 160 PIXEL SCROLL
 
    oBmp:bLClicked := {|| ZOOM_ADJ(oBmp, "M") } // minus
    oBmp:bRClicked := {|| ZOOM_ADJ(oBmp, "P") } // plus
ELSE
    MsgAlert( "Not possible to load Image : " +  CRLF + cWorkFile + CRLF + ;
                    "Please select a new Image !", "Error" )
ENDIF

RETURN( NIL )

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

FUNCTION ZOOM_ADJ(oBmp,cAccion)
LOCAL nZoom0:=oBmp:Zoom()

DO CASE
    CASE cAccion == "S"
        oBmp:lStretch := !oBmp:lStretch
        oBmp:ScrollAdjust()
        oBmp:Refresh( .t. )
    CASE cAccion == "M"
        nZoom++
        IF nZoom0 * 10 > 1
            oBmp:lStretch := .f.
            nZoom0 := nZoom0 - ( 0.10 )
            oBmp:Zoom( nZoom0 )
            oBmp:Refresh()
            oBmp:ScrollAdjust()
        ENDIF
    CASE cAccion == "P"
        oBmp:lStretch := .f.
        nZoom0 := nZoom0 + 0.10
        oBmp:Zoom( nZoom0 )
        oBmp:Refresh()
        oBmp:ScrollAdjust()
ENDCASE

RETURN NIL
 


I still have to find out, how to < crop > from a resized image.

This shows a < Button-solution >

Code: Select all  Expand view

@ nSHeight - 150, nSWidth - 250 BTNBMP oBtn4 OF oWnd ;
SIZE 65, 35 PIXEL 2007 ;
NOBORDER ;
FILENAME c_path + "\Images\Plus.Bmp" ;
ACTION  ZOOM_ADJ(oBmp, "P") ;
FONT oFont2 ;
CENTER
oBtn4:lTransparent := .t.  
oBtn4:cToolTip =  { "Enlarge" + CRLF + "Image","Zoom", 1, CLR_BLACK, 14089979 }
oBtn4:SetColor( 0, )

@ nSHeight - 105, nSWidth - 250 BTNBMP oBtn3 OF oWnd ;
SIZE 65, 35 PIXEL 2007 ;
NOBORDER ;
FILENAME c_path + "\Images\Minus.Bmp" ;
ACTION ZOOM_ADJ(oBmp, "M") ;
FONT oFont2 ;
CENTER
oBtn3:lTransparent := .t.  
oBtn3:cToolTip =  { "Shrink" + CRLF + "Image","Zoom", 1, CLR_BLACK, 14089979 }
oBtn3:SetColor( 0, )
 


Image

Don't forget SCROLL !!!

Image

Image



Best Regards
Uwe :lol:
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: Zoom in on Picture - Uwe

Postby Rick Lipkin » Sat Jun 30, 2012 12:58 pm

Uwe

Thanks .. I will be starting on this inventory module next week ..

Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Zoom in on Picture - Uwe

Postby Rick Lipkin » Thu Jul 12, 2012 10:13 pm

Uwe

Just now working on your suggestion .. in your code in Func Zoom_Adj ..

1) Where does the variable nZoom come from ??

Here is my code and a screen shot .. I do not get any zoom Plus or Minus using the mouse buttons .. I have not put any code behind the 'Zoom' button yet.

Rick Lipkin

Code: Select all  Expand view

 
   REDEFINE IMAGE oImage ID 201 FILENAME NIL OF oInvt;
              PIXEL SCROLL // ADJUST BORDER
   oImage:bPainted := { |hDC| DRAW_IMG( oImage, hDC, cImage, @cPicFileName ) }

   oImage:bLClicked := {|| ZOOM_ADJ(oImage, "M") } // minus
   oImage:bRClicked := {|| ZOOM_ADJ(oImage, "P") } // plus

...
...

// ---------------------
Static Func ZOOM_ADJ(oBmp,cAccion)

LOCAL nZoom0 := oBmp:Zoom()
Local nZoom

nZoom := 10  // just plugged in a number .. no idea where this comes from

msginfo( nZoom0)

DO CASE
    CASE cAccion == "S"
        oBmp:lStretch := !oBmp:lStretch
        oBmp:ScrollAdjust()
        oBmp:Refresh( .t. )
    CASE cAccion == "M"       // minus
        nZoom++
        IF nZoom0 * 10 > 1
            oBmp:lStretch := .f.
            nZoom0 := nZoom0 - ( 0.10 )
            oBmp:Zoom( nZoom0 )
            oBmp:Refresh()
            oBmp:ScrollAdjust()
        ENDIF
     CASE cAccion == "P"        // plus

        msginfo( "In Plus")
        oBmp:lStretch := .f.
        nZoom0 := nZoom0 + 0.10
        oBmp:Zoom( nZoom0 )
        oBmp:Refresh()
        oBmp:ScrollAdjust()
ENDCASE

RETURN NIL


 


.rc

Code: Select all  Expand view

CONTROL "", 201, "TImage", 0 | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, 466, 233, 140, 118
 


Image
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Zoom in on Picture - Uwe

Postby ukoenig » Fri Jul 13, 2012 11:02 am

Rick,

I created a sample from RESOURCE :

Start with original size

Image

Zoom OUT

Image

Zoom IN

Image

Another Solution ( 20 % steps ) :
NO function
NO + / - Buttons
NO Image-click


Image

Code: Select all  Expand view

LOCAL oZSelect1, nZSelect1 := 5 // original

REDEFINE IMAGE oImage ID 510 FILENAME cImage OF oDlg1 PIXEL SCROLL ADJUST BORDER
// NOT NEEDED !!
// oImage:bLClicked := {|| ZOOM_ADJ(oImage, nZoom, "M") } // minus
// oImage:bRClicked := {|| ZOOM_ADJ(oImage, nZoom, "P") } // plus


REDEFINE SELEX oZSelect1 VAR nZSelect1  OF oDlg1 ID 520  ;
ITEMS "-80", "-60", "-40", "-20", "0", "+20", "+40", "+60", "+80", "+100" ;
GRADIENT OUTTRACK { { 0.5, 16443068, 16312263 }, ;
                       { 0.5, 16312263, 16443068 } } ;
GRADIENT INTRACK { { 1, 5426223, 1071100 }, ;
                      { 1, 1071100, 5426223 } } ;
THUMBSIZE 20, 20 ROUNDSIZE 5 ;
COLOR THUMB 14853684 ;
COLORTEXT 128, 32768 ;
TITLE "Image-zoom" TOP ;
FONT oDataFont ;
ACTION ( nZSelect1 := oZSelect1:nOption, ;
        oImage:lStretch := .f., ;
                nZoom := oImage:Zoom(), ;
        IIF( nZSelect1 = 1, nZoom := 0.2, NIL ), ;     
        IIF( nZSelect1 = 2, nZoom := 0.4, NIL ), ;     
        IIF( nZSelect1 = 3, nZoom := 0.6, NIL ), ;     
        IIF( nZSelect1 = 4, nZoom := 0.8, NIL ), ; 
        IIF( nZSelect1 = 5, nZoom := 1, NIL ), ;       
        IIF( nZSelect1 = 6, nZoom := 1.2, NIL ), ;     
        IIF( nZSelect1 = 7, nZoom := 1.4, NIL ), ;     
        IIF( nZSelect1 = 8, nZoom := 1.6, NIL ), ;     
        IIF( nZSelect1 = 9, nZoom := 1.8, NIL ), ;     
        IIF( nZSelect1 = 10, nZoom := 2, NIL ), ;          
                oImage:Zoom( nZoom ), oImage:Refresh(), oImage:ScrollAdjust() ) ;
COLORTITLE 0
 


There seems to be something wrong with the scroll-directions ( very confusing ) :
Right scrollbar-top goes right
Right scrollbar-bottom goes left
Bottom scrollbar-left goes down
Bottom scrollbar-right goes up

Image

Code: Select all  Expand view

// ------------- DIALOG from Resource --------

FUNCTION SHOW_DLG2()
LOCAL hDC, oImage, nZoom := 0 // Counter for plus or minus
LOCAL cImage :=   c_path + "\Images\Trash.bmp"

// DEFINE PATH
//c_path := GETCURDIR()  // New FWH
//IF !FILE( c_path + "\SETTING.INI" ) // a existing File
//  c_path := CURDRIVE() + ":\" + GETCURDIR() // old FWH
//ENDIF

DEFINE DIALOG oDlg1 RESOURCE "Zoom" ;
FONT  oBrwFont TITLE "Dialog from RESOURCE" TRANSPARENT 

// A Dialog-brush-function
//D_BACKGRD( oDlg1, nDStyle, lDDirect, nDColorF, nDColorB, nDGradPos, cDBrush, cDImage )

REDEFINE IMAGE oImage ID 510 FILENAME cImage OF oDlg1 PIXEL SCROLL ADJUST BORDER
oImage:bLClicked := {|| ZOOM_ADJ(oImage, nZoom, "M") } // minus
oImage:bRClicked := {|| ZOOM_ADJ(oImage, nZoom, "P") } // plus

ACTIVATE DIALOG oDlg1 NOWAIT ;
ON INIT ( ZOOM_ADJ(oImage, nZoom, "S"), ; // ON INIT start with normal size
                oDlg1:Move( 60, 30, oDlg1:nWidth, oDlg1:nHeight, .f. ) )

RETURN( NIL )

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

FUNCTION ZOOM_ADJ(oBmp, nZoom, cAccion)
LOCAL nZoom0:=oBmp:Zoom()

DO CASE
    CASE cAccion == "S"
        oBmp:lStretch := !oBmp:lStretch
        oBmp:ScrollAdjust()
        oBmp:Refresh( .t. )
    CASE cAccion == "M"
        nZoom-- // a Counter plus / minus, to remember the zoom-status
        IF nZoom0 * 10 > 1 .or. nZoom < 1
            oBmp:lStretch := .f.
            nZoom0 := nZoom0 - ( 0.20 )  // 0.20 = Zoomfactor 20%
            oBmp:Zoom( nZoom0 )
            oBmp:Refresh()
            oBmp:ScrollAdjust()
        ENDIF
    CASE cAccion == "P"
        nZoom++ // a Counter plus / minus
        oBmp:lStretch := .f.
        nZoom0 := nZoom0 + 0.20
        oBmp:Zoom( nZoom0 )
        oBmp:Refresh()
        oBmp:ScrollAdjust()
ENDCASE

RETURN NIL
 


Best Regards
Uwe :lol:
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: Zoom in on Picture - Uwe

Postby ukoenig » Sat Jul 14, 2012 12:20 pm

Rick,

tested :
aDlgActual := { { nDGradPos, nDColorF, nDColorB }, { nDGradPos, nDColorB, nDColorF } }
SetDlgGradient( aDlgActual )
that works without problems.

working on a Solution, to show and test at runtime
( modified from Logo-painter )

1. select any Image and test with different Brushes
2. test Dialog from CODE or RESOURCE
3. creates a PRG and EXE of the Selections
4. saves Settings to a INI-file


I will have a look at Class Bitmap, because of VScroll and HScroll-directions

Image

Best Regards
Uwe :lol:
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: Zoom in on Picture - Uwe

Postby Rick Lipkin » Sat Jul 14, 2012 2:07 pm

Uwe

Thank you for your help .. I found that the SetDlgGradient() function really messes up the zoom .. I did not realize this until I decided to just create a small self contained example.

Just a simple dialog box like in your example worked as you suggested .. so why did the same code fail in my application ?

I realized SetDlgGradient caused an unintended failure of the zoom .. here is the code with the Gradient function .. compile and run then rem it out re-compile to see the difference.

I read your last post on ( perhaps ) another solution .. don't quite understand the syntax :(

Code: Select all  Expand view

aDlgActual := { { nDGradPos, nDColorF, nDColorB }, { nDGradPos, nDColorB, nDColorF } }
SetDlgGradient( aDlgActual )
 


.. just curious if you can trap the mouse wheel scroll rather than using a Selex control ?

Thanks
Rick

Code: Select all  Expand view

#include "FiveWin.ch"

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

function Main()

local oDlg, oImage,cImage, c_path, nZoom, hDC

c_path := GETCURDIR()
cImage := c_path+"\icetree2.jpg"
nZoom  := 0

*LightGreyGrad()

DEFINE DIALOG oDlg RESOURCE "Test" //TRANSPARENT

   REDEFINE IMAGE oImage ID 201 FILENAME cImage OF oDlg PIXEL SCROLL ADJUST BORDER
   oImage:bLClicked := {|| ZOOM_ADJ(oImage, nZoom, "M") } // minus
   oImage:bRClicked := {|| ZOOM_ADJ(oImage, nZoom, "P") } // plus


   REDEFINE BUTTON ID 120 OF oDlg ;
      ACTION oDlg:End()


ACTIVATE DIALOG oDlg ;
   ON INIT ( oDlg:Move( 60, 30, oDlg:nWidth, oDlg:nHeight, .f. ) )


Return( nil )

// ---------------------
Static Func ZOOM_ADJ(oBmp, nZoom, cAccion)

LOCAL nZoom0:=oBmp:Zoom()

DO CASE
    CASE cAccion == "S"
        oBmp:lStretch := !oBmp:lStretch
        oBmp:ScrollAdjust()
        oBmp:Refresh( .t. )
    CASE cAccion == "M"
        nZoom-- // a Counter plus / minus, to remember the zoom-status
        IF nZoom0 * 10 > 1 .or. nZoom < 1
            oBmp:lStretch := .f.
            nZoom0 := nZoom0 - ( 0.20 )  // 0.20 = Zoomfactor 20%
            oBmp:Zoom( nZoom0 )
            oBmp:Refresh()
            oBmp:ScrollAdjust()
        ENDIF
    CASE cAccion == "P"
        nZoom++ // a Counter plus / minus
        oBmp:lStretch := .f.
        nZoom0 := nZoom0 + 0.20
        oBmp:Zoom( nZoom0 )
        oBmp:Refresh()
        oBmp:ScrollAdjust()
ENDCASE

RETURN NIL

//------------------
Func LightGreyGrad()

SetDlgGradient( { { .50, nRGB( 216, 216, 216 ), nRGB( 255, 255, 255 ) } } )

Return(nil)

// end
 


.rc

Code: Select all  Expand view

Test DIALOG 19, 47, 325, 227
STYLE WS_POPUP | WS_CAPTION
{
 PUSHBUTTON "&OK", 120, 23, 203, 37, 14
 CONTROL "", 201, "TImage", 0 | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, 37, 4, 254, 178
}
 
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Zoom in on Picture - Uwe

Postby ukoenig » Sat Jul 14, 2012 2:20 pm

Rick,

I hope I get it finished this weekend.
That will make it easy, to test the different possible combinations.
The created PRG, You can use inside Your application.
A straight connection to PIXELFORMER is included as well.
It makes it possible, to change something of the selected Image.

The gradient-array saved to var aDlgActual ( nDGradPos = Grad.-pos, nDColorF = 1. Color, nDColorB = 2. Color ) :
aDlgActual := { { nDGradPos, nDColorF, nDColorB }, { nDGradPos, nDColorB, nDColorF } }
SetDlgGradient( aDlgActual )

Best Regards
Uwe :lol:
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: Zoom in on Picture - Uwe

Postby Rick Lipkin » Sat Jul 14, 2012 3:08 pm

Uwe

Thanks
Rick
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 54 guests