BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TImage::OnProgress

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Vincent
Guest





PostPosted: Thu Jun 17, 2004 10:12 am    Post subject: TImage::OnProgress Reply with quote



Little problem :
I just want to show a progress bar when loading a image into a Timage.

But it doesn't work,

here's the code

void __fastcall TForm5::Image2Progress(TObject *Sender,
TProgressStage Stage, BYTE PercentDone, bool RedrawNow,
const TRect &R, const AnsiString Msg)
{
switch (Stage)
{
case psStarting:
CGauge1->Progress=0;
CGauge1->Visible=true;
break;
case psRunning:
CGauge1->Progress=PercentDone;
break;
case psEnding:
CGauge1->Visible=false;
break;
}
}

using breakpoint i can see that i never enter in the routine.

I thought that this routine will called "periodically" when i load a
file intio my image with :

Image2->Picture->Bitmap->LoadFromFile(FileListBox1->FileName);

Any Idea
Thanks Vincent

Back to top
nicolasr
Guest





PostPosted: Thu Jun 17, 2004 1:34 pm    Post subject: Re: TImage::OnProgress Reply with quote



Hi,

I guess that this event is only used with image types that need
to decompress the data before displaying it.

Try

#include <jpeg.hpp> //needed to register jpg file type
....
Image2->Picture->LoadFromFile(FileListBox1->FileName);
....

with a large jpg file and see if the handler is then called.

Nick


Quote:
Little problem :
I just want to show a progress bar when loading a image into a Timage.

But it doesn't work,

here's the code

void __fastcall TForm5::Image2Progress(TObject *Sender,
TProgressStage Stage, BYTE PercentDone, bool RedrawNow,
const TRect &R, const AnsiString Msg)
{
switch (Stage)
{
case psStarting:
CGauge1->Progress=0;
CGauge1->Visible=true;
break;
case psRunning:
CGauge1->Progress=PercentDone;
break;
case psEnding:
CGauge1->Visible=false;
break;
}
}

using breakpoint i can see that i never enter in the routine.

I thought that this routine will called "periodically" when i load a
file intio my image with :

Image2->Picture->Bitmap->LoadFromFile(FileListBox1->FileName);

Any Idea
Thanks Vincent




Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Jun 17, 2004 5:38 pm    Post subject: Re: TImage::OnProgress Reply with quote




"nicolasr" <nicolasrNOSPAMATSIGNgmx.net> wrote


Quote:
I guess that this event is only used with image types
that need to decompress the data before displaying it.

The OnProgress event is optional in TGraphic classes. They are not required
to trigger it during loading/saving. In fact, none of the default graphic
classes (TBitmap, TIcon, TMetaFile, etc) use it at all.


Gambit



Back to top
Andy
Guest





PostPosted: Mon Aug 02, 2004 7:11 am    Post subject: Re: TImage::OnProgress Reply with quote


Hi Vincent,

I had the same problem showing a progress bar when loading a large RTF-File into a TRichEdit with LoadingFromFile.
I found this solution:
First I opened the file with a TFileStream and loaded the data with the LoadFromStream function (which also exists for the TGraphic class).
LoadFromStream access the stream data via the Read method, which is a virtual Method of TFileStream.
So I wrote my own class TMyFileStream derived from TFileStream and overloaded the Read methode:

class TMyFileStream : public TFileStream
{
public:
TProgressBar* progressBar;

public:
TMyFileStream (const String fileName, Word Mode,
TProgressBar* progBar) :
TFileStram (fileName, Mode),
progressBar (progBar) {};

virtual int __fastcall Read(void *Buffer, int Count)
{
progressBar->Position = (float)(Position/Size)*
progressBar->Max;
Application->ProcessMessages ();
return TFileStream::Read (Buffer, Count);
}
}

So whenever LoadFromStream is reading new data via Read I can update the ProgressBar.

Best regards
Andy


Vincent <vincent.vandendaele (AT) trump (DOT) be> wrote:
Quote:
Little problem :
I just want to show a progress bar when loading a image into a Timage.

But it doesn't work,

here's the code

void __fastcall TForm5::Image2Progress(TObject *Sender,
TProgressStage Stage, BYTE PercentDone, bool RedrawNow,
const TRect &R, const AnsiString Msg)
{
switch (Stage)
{
case psStarting:
CGauge1->Progress=0;
CGauge1->Visible=true;
break;
case psRunning:
CGauge1->Progress=PercentDone;
break;
case psEnding:
CGauge1->Visible=false;
break;
}
}

using breakpoint i can see that i never enter in the routine.

I thought that this routine will called "periodically" when i load a
file intio my image with :

Image2->Picture->Bitmap->LoadFromFile(FileListBox1->FileName);

Any Idea
Thanks Vincent



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Aug 02, 2004 8:29 am    Post subject: Re: TImage::OnProgress Reply with quote


"Andy" <Andy-Bauer (AT) gmx (DOT) de> wrote


Quote:
So I wrote my own class TMyFileStream derived from
TFileStream and overloaded the Read methode:

Just as a suggestion, I would recommend exposing an OnProgress event for
that class rather than having it update a progress bar directly. That will
make the code more flexible so that you can use the same code for different
purposes. For example:

enum TFileStreamReadProgressStage { psFileReadStarting, psFileReading,
psFileReadEnding };

typedef void __fastcall (__closure *TMyFileStreamProgress)(TObject
*Sender, TFileStreamReadProgressStage Stage, Byte PercentDone);

class TMyFileStream : public TFileStream
{
protected:
TMyFileStreamProgress FOnProgress;
bool FStarting;
Byte FLastPercent;
public:
__fastcall TMyFileStream(const AnsiString &FileName, Word Mode)
: TFileStream(FileName, Mode), FStarting(true), FLastPercent(0)
{
}

virtual __fastcall ~TMyFileStream()
{
if( (FLastPercent < 100) && (FOnProgress) )
FOnProgress(this, psFileReadEnding, 100);
}

virtual int __fastcall Read(void *Buffer, int Count)
{
if( bStarting )
{
if( FOnProgress )
FOnProgress(this, psFileReadStarting, 0);
bStarting = false;
}

int Result = TFileStream::Read(Buffer, Count);

if( FOnProgress )
{
Byte CurrentProgress = ((Position*100)/Size);
if( CurrentProgress != FLastPercent )
{
FLastPercent = CurrentProgress;
FOnProgress(this, (CurrentProgress < 100) ?
psFileReading : psFileReadEnding, CurrentProgress);
}
}

return Result;
}

__property TMyFileStreamProgress OnProgress = {read=FOnProgress,
write=FOnProgress};
};


void __fastcall TForm1::LoadRichEdit()
{
TMyFileStream *Strm = new TMyFileStream("somefile", fmOpenRead |
fmShareDenyWrite);
try
{
Strm->OnProgress = RichEditLoadProgress;
RichEdit1->LoadFromStream(Strm);
}
__finally{
delete Strm;
}
}

void __fastcall TForm1::RichEditLoadProgress(TObject *Sender,
TFileStreamReadProgressStage Stage, Byte PercentDone)
{
switch( Stage )
{
case psFileReadStarting:
ProgressBar1->Position = 0;
ProgressBar1->Max = 100;
break;
case psFileReading:
ProgressBar1->Position = PercentDone;
break;
case psFileReadEnding:
ProgressBar1->Position = 0;
break;
}
ProgressBar1->Update();
}


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.