Page 1 of 1

clear IMAGE

PostPosted: Thu Jul 18, 2013 8:28 am
by lucasdebeltran
Hello,

I want to set a button (ID 102) to clear the Image:

Code: Select all  Expand view
  REDEFINE IMAGE  oBmpFoto1             ID 103 OF oFld:aDialogs[ 3 ] UPDATE ;
                                                FILENAME oData:FOTO  ;
                                                ON CLICK ( oData:FOTO := _CargaFoto (oBmpFoto1, oDlg)  ) ADJUST

   REDEFINE BUTTON                       ID 101 OF oFld:aDialogs[ 3 ] ;
                                                ACTION ( oData:FOTO := _CargaFoto (oBmpFoto1, oDlg)  )

   REDEFINE BUTTON                       ID 102 OF oFld:aDialogs[ 3 ] ;
                                                ACTION ( oData:FOTO := "", alert(odata:foto), oBmpFoto1:Refresh(), oFld:Update(), oFld:Refresh(), oDlg:Refresh()  )
 



But despite I set oData:Foto to "" and I call refresh and update, the previous picture is still there, I need to remove it.

Maybe I miss something or it is a bug.

Thank you.

Re: clear IMAGE

PostPosted: Thu Jul 18, 2013 5:08 pm
by Gale FORd
I had the same problem in my imaging product. I got around it by creating a blank image "blank,jpg" and using it when there is no image wanted.

Re: clear IMAGE

PostPosted: Thu Jul 18, 2013 5:58 pm
by Rick Lipkin
Lucas

Here is a snipit of code I use for Images with some help and advice from our good friend Uwe.

Have a look at how the image is defined with oImage and bPainted then deleted with the function DelImage()

Rick Lipkin
Code: Select all  Expand view

// images

REDEFINE IMAGE oImage ID 701 FILENAME NIL of oUsers ;
         PIXEL  ADJUST BORDER

     oImage:bPainted := { |hDC| DRAW_IMG( oImage, hDC, cImage, cPicFileName ) }

REDEFINE GET oGET var cImage ID 706 of oUsers PICTURE "@!" READONLY // displays the filename only

REDEFINE BTNBMP oButt4 ID 702 of oUsers ;
         RESOURCE "ADD16","DADD16","DADD16" ;
         PROMPT "Import    " LEFT 2007;
         ACTION ( GetImage( @oImage,oRsPet,oUsers,@cImage,oGet,@cPicFileName ),;
                  _ChkButtons( cMode,oRsPet,oButt4,oButt5,oButt6,oButt7))

REDEFINE BTNBMP oButt5 ID 703 of oUsers ;
         RESOURCE "EDIT16","DEDIT16","DEDIT16" ;
         PROMPT "Export    " LEFT 2007;
         ACTION ( ExportImage( oRsPet,0 ) )

REDEFINE BTNBMP oButt6 ID 704 of oUsers ;
         RESOURCE "DELETE16","DDELETE16", "DDELETE16" ;
         PROMPT "Delete    " LEFT 2007;
         ACTION ( DelImage(@oImage,oRsPet,oUsers,oGet,@cImage,@cPicFileName ),;
                  _ChkButtons( cMode,oRsPet,oButt4,oButt5,oButt6,oButt7))

REDEFINE BTNBMP oButt7 ID 705 of oUsers ;
         RESOURCE "VIEW16","DVIEW16","DVIEW16" ;
         PROMPT "Print      " LEFT 2007;
         ACTION ( PrintImage( oRsPet,0 ) )

// end images

//------------- Image-Brush from Uwe ----------
Static FUNC Draw_Img( oImage, hDC, cImage, cPicFileName  )

LOCAL oBrush,cDefa
LOCAL aRect := GETCLIENTRECT( oImage:hWnd )

cDefa  := set(7)

If cPicFileName = " " // ad mode because blank .. cImage passed as is
Else
   cImage := cDefa+"\Pictures\"+alltrim( cImage )
Endif

// added for on paint
SysReFresh()

IF FILE( cImage )
    DEFINE IMAGE oBrush FILENAME cImage
    PalBmpDraw( hDC, 0, 0, oBrush:hBitmap, , aRect[4], aRect[3] )
    oBrush:End()
ENDIF

RETURN( NIL )

//----------------------------------------------------------------------------//
Static Func DelImage( oImage,oRsPet,oDlg,oGet,cImage,cPicFileName )

LOCAL Saying,cFILE,cDefa

cDefa := set(7)
cFile := oRsPet:Fields("
PicFileName"):Value

If cFile = "
" .or. empty( cFile )
   Saying := "
Sorry .. there is no Image to Delete"
   MsgInfo( Saying )
   Return(.f.)
Endif

Saying := "
Are you SURE you want to Delete this Image ?"+chr(10)
Saying += cFile

If MsgNoYes( Saying )

   Ferase(cDefa+"
\Pictures\"+alltrim(cFile))
   cImage := "
"
   oGet:Refresh()
   oImage:Refresh()
   oDlg:ReFresh()
   SysReFresh()

   cPicFileName := space(50)
   oRsPet:Fields("
PicFileName"):Value := cPicFileName
   oRsPet:Update()

   SysReFresh()

Endif

Return(nil)

Re: clear IMAGE

PostPosted: Thu Jul 18, 2013 6:14 pm
by nageswaragunupudi
Mr Lucas

Let me try to make it simple for you.

#1. If you want to change the image with a new image file :
ACTION ( oData:foto := <newfilename>, oImage:LoadBmp( oData:foto ) )

#2. If you want to clear image
ACTION ( oData:foto := "", ClearImage( oImage ) )

I shall give you a function to ClearImage
Code: Select all  Expand view
function ClearImage( oBmp )

   WITH OBJECT oBmp
      PalBmpFree( :hBitmap, :hPalette )
      :hBitmap := :hPalette  := 0
      :cBmpFile := :cResName := nil
      :Refresh()
   END

return nil
 


We try to provide an appropriate method in the class in the next version.

Re: clear IMAGE

PostPosted: Thu Jul 18, 2013 6:15 pm
by elvira
Lucas;

Try this oBmpFoto1:LoadImage("nada")

Re: clear IMAGE

PostPosted: Thu Jul 18, 2013 8:36 pm
by nageswaragunupudi
elvira wrote:Lucas;

Try this oBmpFoto1:LoadImage("nada")

This also works. Giving a non-empty name, which is not an existing image file also works. This is a work around.

Re: clear IMAGE

PostPosted: Sat Aug 03, 2013 2:11 pm
by nageswaragunupudi
From FWH 13.07, we can use
oImg:Clear()