ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Progress bar
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

pierrotsc

USA
499 Posts

Posted - Jun 04 2013 :  13:23:18  Show Profile  Reply
Is there a way to have the progress bar to display the length of a process that is currently happening?
The code below makes PC (Slower mostly) unresponsive. The user thinks that the computer has frozen but it is not the case in reality.
It would be nice to see a progress bar moving while Imageen is processing.
This is an example of the code i am using.
Imageen.layersclear;
screen.cursor := crhourglass;
MS:= tmemorustream.create;
imageenview.savetostream(ms,-1)
imageenview.copyobjectstoback(true)
imageenview.layersmergeall
imageenview.update
Imageenview.layersdrawto(imageenvect.iebitmap)
imageenvect.update
imageenvect.proc.negative
red:= imageenvect.proc.getrgbchannel(2)
imageenvect.currentlayer.bitmap.assign(red)
imageenvect.layersremove(0)
imageenvect.update;
imageenvect.proc.flip(fdhorizontal)
Imageenvect.layersadd
Imageenvect.proc.castcolor(0,0,255,0,0,0)
imageenvect.layersmergeall
imageenvect.io.doprintpreviewdialog(iedtdialog)

I know it's heavy but if there is a way to show a progress, that would be great.
Thanks.
P

w2m

USA
1990 Posts

Posted - Jun 04 2013 :  15:46:03  Show Profile  Reply
Time consuming code is best handled in a thread. That said the only alternative is to add Application.ProcessMessages to ImageEn's OnProgress event:
procedure TForm1.ImageEnViewProgress(Sender: TObject; per: Integer);
{ Respond to Progress. }
begin
  ProgressBar1.Position := per;
  Application.ProcessMessages;
end;

See http://delphi.about.com/od/objectpascalide/a/delphi-processmessages-dark-side.htm

Unfortunately thread development can be difficult. There are a number of components that make handling a time consuming operation in a thread easier. One of the simplest to use is:
http://www.delphiarea.com/products/delphi-components/backgroundworker/

It has good help and is free. Of the two approaches the backgroundworker is your best choice.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

pierrotsc

USA
499 Posts

Posted - Jun 04 2013 :  16:21:26  Show Profile  Reply
Thank you..Let me look at the second option.
Go to Top of Page

pierrotsc

USA
499 Posts

Posted - Jun 04 2013 :  17:37:14  Show Profile  Reply
I have a question though. I would like to use only one backgroundworker component for a few different process. How do I code the onwork event to reflect for example:
MS:= tmemorustream.create;
imageenview.savetostream(ms,-1)
imageenview.copyobjectstoback(true)
imageenview.layersmergeall
imageenview.update

I know it is not an imageen question but any help would be appreciated.
Thanks.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jun 05 2013 :  04:55:55  Show Profile  Reply
Just put all the "work" code in the OnWork Event.
and put progressbar code here:
procedure TForm1.BackgroundWorker1WorkProgress(Worker: TBackgroundWorker; PercentDone: Integer);
begin
  ProgressBar1.Position := PercentDone;
end;

Also show working code. ImageEnView1.CopyObjectsToBack(true); is incorrect because ImageEnView1 can not contain objects and what do you do with the memory stream?

In any event make sure by repeated testing that the code you process the image with works flawlessly outside of the thread. If it does bot function perfectly once you put the work in a thread the thread will fail. You may also be able to just use this but you will have to test it:
procedure TForm1.ImageEnVect1FinishWork(Sender: TObject);
begin
  ProgressBar1.Position := 0;
end;

procedure TForm1.ImageEnVect1Progress(Sender: TObject; per: Integer);
begin
  ProgressBar1.Position := per;
end;


When testing the processing the image in a thread sometimes it is best to do the final tests outside of the IDE by running the EXE all by itself.

If you send me your email address I'll send you a demo of Backgroundworker with ImageEn Demo. I had to modify your processing code as yours would not compile.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

pierrotsc

USA
499 Posts

Posted - Jun 05 2013 :  07:49:29  Show Profile  Reply
Sure..Here it is unglobetrotteur@hotmail.com

For the event question, I want to code it by hand. I want to re use the backgroundworker a few times for different command, so i want to leave the onwork event empty in the component and add the code i want when I need it before calling the execute command. I hope i am making sense.
I will wait to see your code and that may help me understand better.
Thanks.

PS: The memory stream is used to restore the image the way it was before i merged everything. I did not add the code in my first question.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jun 05 2013 :  08:08:06  Show Profile  Reply
Hotmail does not accept attachments so I need an email address that allows attachments.

I think in order for the thread to work correctly all the work done in the background must be done in the OnWorkEvent.

In your case I would think you would use a unique backgroundworker component for each different command. Think of each backgroundworker as a unique thread that processes each command in its OnWorkEvent.

You might be able to use just one BackgroundWorker component and use a different OnWorkEvent for each command:
Button1Click:
BackgroundWorker1.OnWork := BackgroundWorker1Work1;
Button2Click:
BackgroundWorker1.OnWork := BackgroundWorker1Work2;
Button3Click:
BackgroundWorker1.OnWork := BackgroundWorker1Work3;

My guess is that without image processing code in the OnWorkEvent, the thread will do nothing and will be useless and the processing you do will not be threaded.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: