change or put an image

change or put an image

Postby plantenkennis » Tue Oct 18, 2016 9:19 pm

I have a window with several tabs. On one tab I can put up to 15 small images. With a button I can select a new image to put on this tab. But how do I show this image? I have tried using setimage(), but that gives an error. Here is my code:
Code: Select all  Expand view
   
*tab 3, in array aFotoNaam are the names of the images
     nRowPaint   := 450
        nColumn     := 10
nfotoToon := 1

        FOR r = 1 TO 3
            FOR k = 1 TO 5
                cImage := aFotoNaam[nFotoToon]
                oImgName := 'oImg' + ALLTRIM(STR(nFoto))
                    @ nRowPaint, nColumn IMAGE &oImgName FILENAME cImage OF oFld:aControls[ 3 ] SIZE 110, 110
                nColumn := nColumn + 120
                nFotoToon++
            NEXT
            nColumn := 10
            nRowPaint := nRowPaint - 120
        NEXT

        @ 40, 650 BUTTON "New photo" OF oFld:aDialogs[ 3 ] ACTION RK_SelectFoto(nPlantnum) SIZE 120, 30

FUNCTION RK_SelectFoto(nPlantnum)
*to select a picture, resize it and place it in the right folder
*28-09-2016

LOCAL oWndFoto, oBtnOK
LOCAL oFoto
LOCAL cFoto := ''
LOCAL cKopie := ''
LOCAL nMaxWidth := 1000
LOCAL nMaxHeight := 800
LOCAL nFotoWidth
LOCAL nFotoHeight
LOCAL nFactor := 0

*choose photo
cFoto := ChooseFile( "Selecteer een foto", "jpg" )
IF LEN(ALLTRIM(cFoto)) > 0
    nFoto++
    cKopie := cPath + '/temp/' + ALLTRIM(STR(nPlantnum+nFoto)) + '.jpg'

    *define a window to check the size of the photo
    DEFINE DIALOG oWndFoto TITLE "grote foto" ;
        FROM 0, 0 TO 800, 800
       
        @ 40, 10 IMAGE oFoto FILENAME cFoto OF oWndFoto SIZE 640, 480

    *check the size of the photo
        nFotoWidth := oFoto:GetWidth()
        nFotoHeight := oFoto:GetHeight()

    *if the photo is too wide, set the right width
        IF nFotoWidth > 1000
            nFactor := 1000 / nFotoWidth
            nFotoWidth := 1000
            nFotoHeight  := ROUND(nFotoHeight * nFactor, 0)
        ENDIF
    *if the photo is still to high, set the right height
        IF nFotoHeight > 800
            nFactor := 800 / nFotoHeight
            nFotoHeight := 800
            nFotoWidth  := ROUND(nFotoWidth * nFactor, 0)
        ENDIF

    *now rescale the IMAGE
        oFoto:SetSize( nFotoWidth, nFotoHeight )
           oFoto:SetScaling( 1 )  
        oWndFoto:SetSize( nFotoWidth + 20, nFotoHeight + 40 )

        @ 10, nFotoWidth BUTTON oBtnOK PROMPT "Ok" OF oWndFoto ACTION oWndFoto:End()

    ACTIVATE DIALOG oWndFoto

    *and save the rescaled image in the temp folder
    SaveImageFromImage( cFoto, cKopie, nFotoWidth, nFotoHeight )
    *add the name to the foto array
    aFotoNaam[nFoto] := cKopie
    *show the new image
    oImgName := 'oImg' + ALLTRIM(STR(nFoto))
*       &oImgName:setImage( cKopie )
        ImgSetNSImage(::oDlgChange,cKopie)
   
ENDIF

RETURN


 


René
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: change or put an image

Postby Antonio Linares » Tue Oct 18, 2016 10:42 pm

René,

Please update the repository and I will pull it and check it
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: change or put an image

Postby Antonio Linares » Wed Oct 19, 2016 6:06 pm

Please use the message SetFile() instead of SetImage()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: change or put an image

Postby plantenkennis » Wed Oct 19, 2016 6:14 pm

Hello Antonio,

I have updated the repository.
The problem is the use of the &oImg. The program awnsers with Not Defined?

René
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: change or put an image

Postby Antonio Linares » Wed Oct 19, 2016 6:46 pm

René,

Please try it this way:

Code: Select all  Expand view
 

        @ 40, 650 BUTTON "New photo" OF oFld:aDialogs[ 3 ] ACTION RK_SelectFoto(nPlantnum, &oImgName ) SIZE 120, 30

...

FUNCTION RK_SelectFoto( nPlantnum, oImgName )

   ...

  oImgName:setImage( cKopie )

RETURN
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: change or put an image

Postby plantenkennis » Fri Oct 21, 2016 9:26 am

Hello Antonio,

This code does not work. I get an error: Code block contains both macro and declared symbol references 'NPLANTNUM'

I will try some other things next days

Regards,
René
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: change or put an image

Postby Antonio Linares » Fri Oct 21, 2016 9:38 am

In which of the 15 images the new image should be placed at ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: change or put an image

Postby plantenkennis » Fri Oct 21, 2016 10:46 am

Hello Antonio,

In which image it should be placed is depending on the number of photo's I have from that plant. So if a plant has 3 photo's, the new image should be placed on number 4.
I will try another approach be defining several buttons where I can add a new image. By hiding most of them and using the function to work with macro substitution it will work, I hope.

Regards,
René
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: change or put an image

Postby Antonio Linares » Fri Oct 21, 2016 7:49 pm

René,

> the number of photo's I have from that plant

if you know such number in advance then you can do:

{ oImage1, ..., oImage15 }[ nNewPhoto ]:SetFile( cFileName )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: change or put an image

Postby plantenkennis » Tue Oct 25, 2016 8:52 pm

Hello Antonio,

The action with arrays did not work, but I have another solution:
I create buttons under the picture and with these buttons I can move an image and add or delete one. But how can I disable or enable a BTNBMP. This works with BUTTON, but not with BTNBMP. But the bAction works with BTNBMP but not with BUTTON?
Here is my code:

Code: Select all  Expand view
        FOR r = 1 TO 3
            FOR k = 1 TO 5
                cImage := cPath + "/temp/" + ALLTRIM(STR(nPlantnum + r*k)) + ".jpg"
                oImgName := 'oImg' + ALLTRIM(STR(r*k))
                oBtnLeftName := 'oBtnLeft' + ALLTRIM(STR(r*k))
                oBtnRightName := 'oBtnRight' + ALLTRIM(STR(r*k))
                oBtnNewName := 'oBtnNew' + ALLTRIM(STR(r*k))
                oBtnDelName := 'oBtnDel' + ALLTRIM(STR(r*k))
               
                    @ nRowPaint, nColumn IMAGE &oImgName FILENAME cImage OF oFld:aControls[ 3 ] SIZE 110, 110
                            &oImgName:setframe()
                    @ nRowPaint-40, nColumn BTNBMP &oBtnLeftName OF oFld:aControls[ 3 ] FILENAME ImgPath()+"Left.png"  SIZE 35, 35 STYLE 2 TOOLTIP "Foto naar links"
                        &oBtnLeftName:bAction := CreateBlock(oBtnLeftName)
                    @ nRowPaint-40, nColumn+40 BTNBMP &oBtnNewName OF oFld:aControls[ 3 ] FILENAME ImgPath()+"Add.png" SIZE 35, 35 STYLE 2 TOOLTIP "Nieuwe foto"
                        &oBtnNewName:bAction := CreateBlock(oBtnNewName)
                    @ nRowPaint-40, nColumn+40 BTNBMP &oBtnDelName OF oFld:aControls[ 3 ] FILENAME ImgPath()+"Delete.png" SIZE 35, 35 STYLE 2 TOOLTIP "Verwijder Foto"
                        &oBtnDelName:bAction := CreateBlock(oBtnDelName)
                    @ nRowPaint-40, nColumn+80 BTNBMP &oBtnRightName OF oFld:aControls[ 3 ] FILENAME ImgPath()+"Right.png" SIZE 35, 35 STYLE 2 TOOLTIP "Foto naar rechts"
                        &oBtnRightName:bAction := CreateBlock(oBtnRightName)
                nColumn := nColumn + 130
            NEXT
            nColumn := 10
            nRowPaint := nRowPaint - 150
        NEXT
RK_SetButtons()

*************************************************

FUNCTION RK_SetButtons()

FOR n = 1 TO 15
    oBtnLeftName := 'oBtnLeft' + ALLTRIM(STR(n))
    oBtnRightName := 'oBtnRight' + ALLTRIM(STR(n))
    oBtnNewName := 'oBtnNew' + ALLTRIM(STR(n))
    oBtnDelName := 'oBtnDel' + ALLTRIM(STR(n))

    IF n == 1
        oBtnLeftName:Disable()
    ENDIF
    IF n < nFoto
        oBtnNewName:Disable()
    ENDIF
    IF n == nFoto
        oBtnRightName:Disable()
    ENDIF
    IF n > nFoto
        oBtnLeftName:Disable()
        oBtnRightName:Disable()
        oBtnDelName:Disable()
        oBtnNewName:Disable()
    ENDIF
NEXT
oBtnNewName := 'oBtnNew' + ALLTRIM(STR(nFoto+1))
oBtnNewName:Enable()

RETURN NIL

 


I have pushed my latest code to BitBucket

Rene
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: change or put an image

Postby plantenkennis » Sat Oct 29, 2016 3:17 pm

Hello Antonio,
I have taken a complete new approach for the adding and changing images. Instead of showing all the images at once I put the names of the images in an array and show one of the images when i click on an item of a listbox. Now I am able to disable and enable buttons. Here is the code I now use:
Code: Select all  Expand view

        @ 140, 10 LISTBOX oBrwFoto FIELDS "", "" ;
            HEADERS "Fotos", "" ;
            OF oFld:aDialogs[ 3 ] SIZE 150, 400
            oBrwFoto:SetArray( aFotoChange )
            oBrwFoto:bLine = { | nRow | IF( nRow <= Len( aFotoChange ), aFotoChange[ nRow ], { "", "" } ) }
            oBrwFoto:SetColWidth( 1, 150 )
            oBrwFoto:SetColWidth( 2, 0 )
            oBrwFoto:SetColEditable( 2, .F. )
            oBrwFoto:SetColor( OwnClrGreen, OwnClrYellow )
            oBrwFoto:Select( 1 )
            oBrwFoto:bChange := { | obj , nindex| oImgChange:SetFile(aFotoChange[obj:nRowPos(), 2]), nRowSelected := obj:nRowPos(), IF(nRowSelected == 1, oBtnUp:Disable(), oBtnUp:Enable()), IF(nRowSelected == LEN(aFotoChange), oBtnDown:Disable(), oBtnDown:Enable())}

        @  40, 200 IMAGE oImgChange FILENAME aFotoChange[1,2] OF oFld:aControls[ 3 ] SIZE 500, 500
                oImgChange:setframe()
               
        @ 100,  10 BUTTON oBtnNew PROMPT '' OF oFld:aControls[ 3 ] ACTION RK_SelectFoto() FILENAME ImgPath()+"Add.png"  SIZE 35, 35 STYLE 2
        @ 100,  50 BUTTON oBtnDel PROMPT '' OF oFld:aControls[ 3 ] ACTION RK_DeletePict(nRowSelected) FILENAME ImgPath()+"Delete.png"  SIZE 35, 35 STYLE 2
        @ 100,  90 BUTTON oBtnUp PROMPT '' OF oFld:aControls[ 3 ] ACTION RK_MovePict(nRowSelected, -1) FILENAME ImgPath()+"Up.png"  SIZE 35, 35 STYLE 2
        @ 100, 130 BUTTON oBtnDown PROMPT '' OF oFld:aControls[ 3 ] ACTION RK_MovePict(nRowSelected, 1) FILENAME ImgPath()+"Down.png"  SIZE 35, 35 STYLE 2
       
        IF nFoto == 15
            oBtnNew:Disable()
        ENDIF
FUNCTION RK_SelectFoto()
*to select a picture, resize it and place it in the right folder
*28-09-2016

LOCAL oWndFoto, oBtnOK
LOCAL oFoto
LOCAL cFoto := ''
LOCAL nMaxWidth := 1000
LOCAL nMaxHeight := 800
LOCAL nFotoWidth
LOCAL nFotoHeight
LOCAL nFactor := 0

*choose photo
cFoto := ChooseFile( "Selecteer een foto", "jpg" )
IF LEN(ALLTRIM(cFoto)) > 0
    nFoto++
    cKopie := cPath + '/temp/' + ALLTRIM(STR(nPlantnum+nFoto)) + '.jpg'

    *define a window to check the size of the photo
    DEFINE DIALOG oWndFoto TITLE "grote foto" ;
        FROM 0, 0 TO 800, 800
       
        @ 40, 10 IMAGE oFoto FILENAME cFoto OF oWndFoto SIZE 640, 480

    *check the size of the photo
        nFotoWidth := oFoto:GetWidth()
        nFotoHeight := oFoto:GetHeight()

    *if the photo is too wide, set the right width
        IF nFotoWidth > 1000
            nFactor := 1000 / nFotoWidth
            nFotoWidth := 1000
            nFotoHeight  := ROUND(nFotoHeight * nFactor, 0)
        ENDIF
    *if the photo is still to high, set the right height
        IF nFotoHeight > 800
            nFactor := 800 / nFotoHeight
            nFotoHeight := 800
            nFotoWidth  := ROUND(nFotoWidth * nFactor, 0)
        ENDIF

    *now rescale the IMAGE
        oFoto:SetSize( nFotoWidth, nFotoHeight )
           oFoto:SetScaling( 1 )  
        oWndFoto:SetSize( nFotoWidth + 20, nFotoHeight + 40 )

        @ 10, nFotoWidth-100 BUTTON oBtnOK PROMPT "Ok" OF oWndFoto ACTION oWndFoto:End()

    ACTIVATE DIALOG oWndFoto

    *and save the rescaled image in the temp folder
    SaveImageFromImage( cFoto, cKopie, nFotoWidth, nFotoHeight )
    AADD(aFotoChange, {'foto '+ ALLTRIM(STR(nFoto)), cKopie} )
    oBrwFoto:Refresh()
    oBrwFoto:Select( nFoto )
    oBrwFoto:SetFocus()
   
    IF nFoto == 15
        oBtnNew:Disable()
    ENDIF
   
ENDIF

RETURN

*************************************************
FUNCTION RK_MovePict(nFotoNum, nMove)

*LOCAL cBestand1 := cPath + '/temp/' + ALLTRIM(STR(nPlantnum + nFotonum)) + '.jpg'
*LOCAL cBestand2 := cPath + '/temp/' + ALLTRIM(STR(nPlantnum + nFotonum +nMove)) + '.jpg'
LOCAL cBestand1 := aFotoChange[nFotoNum,2]
LOCAL cBestand2 := aFotoChange[nFotoNum+nMove,2]
LOCAL cTemp := cPath + '/temp/temp.jpg'

    COPY FILE &cBestand1 TO &cTemp
    IF FERASE(cBestand1) <> 0
        MsgInfo('fout bij het verplaatsen van de foto')
    ENDIF
    COPY FILE &cBestand2 TO &cBestand1
    IF FERASE(cBestand2) <> 0
        MsgInfo('fout bij het verplaatsen van de foto')
    ENDIF
    COPY FILE &cTemp TO &cBestand2
    IF FERASE(cTemp) <> 0
        MsgInfo('fout bij het verplaatsen van de foto')
    ENDIF

aFotoChange[nFotoNum,2] := cBestand1
aFotoChange[nFotoNum+nMove,2] := cBestand2
    oBrwFoto:Refresh()
    oBrwFoto:Select( nFotoNum+nMove )
    oBrwFoto:SetFocus()

RETURN

*************************************************


 

Image
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: change or put an image

Postby Antonio Linares » Sat Oct 29, 2016 6:39 pm

René,

great!

Is it working fine then now ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: change or put an image

Postby plantenkennis » Sun Oct 30, 2016 4:27 pm

Hello Antonio,

Yes, the solution I have made is perfect.

"Sometimes, if things don't work the way you want, want them the way they work."

Again I am one step further in developing my program.

René
Kind regards,

René Koot
User avatar
plantenkennis
 
Posts: 166
Joined: Wed Nov 25, 2015 7:13 pm
Location: the Netherlands

Re: change or put an image

Postby Antonio Linares » Sun Oct 30, 2016 7:54 pm

very good :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveMac / FivePhone (iPhone, iPad)

Who is online

Users browsing this forum: No registered users and 13 guests