clear tImage

clear tImage

Postby Natter » Tue Jul 22, 2008 9:36 pm

Hi all !
I created image

oIm:=tImage():New()
oIm:LoadBmp(cFile)

I want delete BMP from oIm. How do it ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Postby StefanHaupt » Tue Jul 22, 2008 9:53 pm

Natter,

if you want to change the image just load load a new one
oIM:SetBmp(cResName) or oIM:ReLoad( cResName, cBmpFile )

if you want to delete the bmp you can destroy the object, just write oIM := nil or you try to load an unexisting image (not tested)
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Postby Natter » Tue Jul 22, 2008 10:09 pm

... delete the bmp you can destroy the object, just write oIM := nil or you try to load an unexisting image (not tested)"

I do it. It's not work
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Postby ralph » Wed Jul 23, 2008 3:59 am

try this:

oIm:hbitmap := 0
oIm:Refresh()



Ralph
User avatar
ralph
 
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Postby Natter » Wed Jul 23, 2008 6:19 am

It's not work
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Postby mmercado » Wed Jul 23, 2008 7:19 am

Natter wrote:It's not work
May be:
Code: Select all  Expand view
PalBmpFree( oIm:hBitMap, oIm:hPalette )
Regards.

Manuel Mercado.
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby Enrico Maria Giordano » Wed Jul 23, 2008 9:45 am

This is a sample:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg, oImg

    DEFINE DIALOG oDlg;
           SIZE 700, 500

    @ 1, 1 IMAGE oImg;
           FILE "SFONDO.JPG";
           SIZE 200, 200;
           ADJUST

    @ 0,  1 BUTTON "Save";
            ACTION MSGINFO( oImg:SaveImage( "SAVED.JPG", 2 ) )

    @ 0,  7 BUTTON "Print";
            ACTION PRINT( oImg )

    @ 0, 13 BUTTON "Paste";
            ACTION ( oImg:LoadFromClipboard(),;
                     oImg:Refresh() )

    @ 0, 19 BUTTON "Load";
            ACTION ( oImg:LoadImage( , "GRIGIO.JPG" ),;
                     oImg:Refresh() )

    @ 0, 25 BUTTON "Clear";
            ACTION ( PalBmpFree( oImg:hBitMap, oImg:hPalette ),;
                     oImg:hBitmap := 0,;
                     oImg:hPalette := 0,;
                     oImg:cResName := NIL,;
                     oImg:cBmpFile := NIL,;
                     oImg:Refresh() )

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


STATIC FUNCTION PRINT( oImg )

    LOCAL oPrn

    PRINT oPrn PREVIEW MODAL
        PAGE
            oPrn:SayImage( 0, 0, oImg, oPrn:nHorzRes(), oPrn:nVertRes() )
        ENDPAGE
    ENDPRINT

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Wed Jul 23, 2008 12:58 pm

It looks like the TImage class needs an End() method.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby mmercado » Wed Jul 23, 2008 3:29 pm

James Bott wrote:It looks like the TImage class needs an End() method.
Hi James:

It has. TImage is a TBitmap subclass, then inherits Destroy Method.

Best regards.

Manuel Mercado
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby Natter » Wed Jul 23, 2008 4:56 pm

Thank everybody !

@ 0, 25 BUTTON "Clear";
ACTION oImg:hBitmap := 0, ;
oImg:cBmpFile := NIL,;
oImg:Refresh() )

It work right !
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Postby James Bott » Wed Jul 23, 2008 4:59 pm

It has. TImage is a TBitmap subclass, then inherits Destroy Method.


It is not clear if we should call the Destroy() method or the End() method. I see that TBitmap inherits from TControl which inherits from TWindow, yet I do not see the Destroy() method being called by any of those classes' End() method.

To be consistant with all the other classes, the End() method should be the one that ends the object.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Wed Jul 23, 2008 5:01 pm

Natter,

Try calling oImg:End() or oImg:Destroy() to see if one of those also works.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Natter » Wed Jul 23, 2008 5:21 pm

1) calling oImg:End() - this method deleted control
2) calling oImg:Destroy() - this method not work right.
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Postby Enrico Maria Giordano » Wed Jul 23, 2008 5:36 pm

Natter wrote:Thank everybody !

@ 0, 25 BUTTON "Clear";
ACTION oImg:hBitmap := 0, ;
oImg:cBmpFile := NIL,;
oImg:Refresh() )

It work right !


It's not enough. Please use what I put in my sample if you don't want to have resource leak.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 59 guests