Board index » delphi » how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

how can I repaint every half second a TPaintBox with a JPEG from a Web Server?


2005-11-18 01:09:16 AM
delphi214
Hello,
to prevent flickering we would like to use a TPaintBox instead of a TImage.
The image we would like use comes from a web Server and it is a JPEG.
We need to update the image every 300/500ms.
Any help will be very precious..
Thanks in advance,
Gianluca
 
 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

TPaintBox will only gain you speed not flicker reduction. For flicker
reduction you need Double Buffering.
Basically create a TJPEGImage, load your file, and then perform the draw to
the paintboxes canvas or move the canvas handles to perform faster
refreshes.
Jeremy
"Gianluca" <XXXX@XXXXX.COM>writes
Quote
Hello,

to prevent flickering we would like to use a TPaintBox instead of a
TImage.
The image we would like use comes from a web Server and it is a JPEG.
We need to update the image every 300/500ms.

Any help will be very precious..

Thanks in advance,
Gianluca

 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

In article <XXXX@XXXXX.COM>, Gianluca writes:
Quote
to prevent flickering we would like to use a TPaintBox instead of a TImage.
The image we would like use comes from a web Server and it is a JPEG.
We need to update the image every 300/500ms.

Any help will be very precious..
Well, download the image and load it into a TJPegImage instance the paintbox
can "see", then call the paintboxes Invalidate method to force it to repaint.
The rest of the work is done in the paintboxes OnPaint handler. It should be
something like this:
procedure tFormX.Paintbox1Paint(sender: TObject);
var
PB: TPaintbox;
R : TRect;
begin
PB:= Sender as TPaintbox;
R:= PB.ClientRect;
if Assigned( Jpeg ) then begin
PB.Canvas.Draw(0, 0, Jpeg);
if Jpeg.Width < PB.ClientWidth then begin
R.Left := Jpeg.Width;
PB.Canvas.FillRect(R);
R.Right := R.Left;
R.Left := 0;
end;
if Jpeg.Height < PB.CLientHeight then begin
R.Top := Jpeg.Height;
PB.Canvas.FillRect(R);
end;
end
else
PB.Canvas.FillRect(R);
end;
Untested, of course.
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be
 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

Gianluca writes:
Quote
to prevent flickering we would like to use a TPaintBox instead of a TImage.
The image we would like use comes from a web Server and it is a JPEG.
We need to update the image every 300/500ms.
One frame every half second would really be pushing it for most
combinations of image size and bandwidth that I can think of. Why not
use a video stream?
Cheers,
Nicholas Sherlock
 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

Hi,
first of all thanks for the support.
At the moment we are doing something like the following code.
Please could you explain us what do you mean with:
1. to use a double buffer
2. move the canvas handles to perform faster refreshes
Thanks in advance
Gianluca
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
procedure TForm1.GetImage(pixURL: String);
var
ImageStream: TMemoryStream;
HTTP: TIdHTTP;
begin
ImageStream := TMemoryStream.Create;
HTTP := TIdHTTP.Create(Self);
HTTP.RecvBufferSize := 99999;
try
HTTP.Get(pixURL, ImageStream);
ImageStream.Position := 0;
try
mJPEG.LoadFromStream(ImageStream);
finally
PaintBox1.Invalidate;
end;
finally
ImageStream.Free;
HTTP.Free;
end;
end;
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
lPaintBox: TPaintbox;
begin
lPaintBox:= Sender as TPaintbox;
if Assigned( mJPEG ) then begin
lPaintBox.Canvas.Draw(0, 0, mJPEG);
end;
"Jeremy Darling" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
TPaintBox will only gain you speed not flicker reduction. For flicker
reduction you need Double Buffering.

Basically create a TJPEGImage, load your file, and then perform the draw
to the paintboxes canvas or move the canvas handles to perform faster
refreshes.

Jeremy

"Gianluca" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Hello,
>
>to prevent flickering we would like to use a TPaintBox instead of a
>TImage.
>The image we would like use comes from a web Server and it is a JPEG.
>We need to update the image every 300/500ms.
>
>Any help will be very precious..
>
>Thanks in advance,
>Gianluca
>


 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

Hi,
as soon as we know the web server we are connected exports only a \getImage
method; more, spying the net traffic between the Web Server and a
Client(Demo), we get that the \getImage method is called every 300ms. With
that demo, the "video"(the rapid sequency of the downloaded jpeg images) is
showed well and without time loss or flick.
We are not very "inside" the video streaming or Motion Jpeg, so, if you have
any suggestion it will be welcome.
Gianluca
"Nicholas Sherlock" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
Gianluca writes:
>to prevent flickering we would like to use a TPaintBox instead of a
>TImage.
>The image we would like use comes from a web Server and it is a JPEG.
>We need to update the image every 300/500ms.

One frame every half second would really be pushing it for most
combinations of image size and bandwidth that I can think of. Why not use
a video stream?

Cheers,
Nicholas Sherlock
 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

Look in borland.public.attachments I have placed a simple sample application
their that shows everything you need to know and does it with jpeg's. Note
though that properly the read and buffer swap should really be done in a
thread. I have done it in the VCL thread just to keep things simple. The key
really is the ControlStyle setup :).
Jeremy
"Gianluca" <XXXX@XXXXX.COM>writes
Quote
Hi,
first of all thanks for the support.

At the moment we are doing something like the following code.
Please could you explain us what do you mean with:
1. to use a double buffer
2. move the canvas handles to perform faster refreshes

Thanks in advance
Gianluca

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
procedure TForm1.GetImage(pixURL: String);
var
ImageStream: TMemoryStream;
HTTP: TIdHTTP;
begin
ImageStream := TMemoryStream.Create;
HTTP := TIdHTTP.Create(Self);
HTTP.RecvBufferSize := 99999;
try
HTTP.Get(pixURL, ImageStream);
ImageStream.Position := 0;
try
mJPEG.LoadFromStream(ImageStream);
finally
PaintBox1.Invalidate;
end;
finally
ImageStream.Free;
HTTP.Free;
end;
end;

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*}
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
lPaintBox: TPaintbox;
begin
lPaintBox:= Sender as TPaintbox;
if Assigned( mJPEG ) then begin
lPaintBox.Canvas.Draw(0, 0, mJPEG);
end;






"Jeremy Darling" <XXXX@XXXXX.COM>ha scritto nel messaggio
news:437cc79e$XXXX@XXXXX.COM...
>TPaintBox will only gain you speed not flicker reduction. For flicker
>reduction you need Double Buffering.
>
>Basically create a TJPEGImage, load your file, and then perform the draw
>to the paintboxes canvas or move the canvas handles to perform faster
>refreshes.
>
>Jeremy
>
>"Gianluca" <XXXX@XXXXX.COM>writes
>news:XXXX@XXXXX.COM...
>>Hello,
>>
>>to prevent flickering we would like to use a TPaintBox instead of a
>>TImage.
>>The image we would like use comes from a web Server and it is a JPEG.
>>We need to update the image every 300/500ms.
>>
>>Any help will be very precious..
>>
>>Thanks in advance,
>>Gianluca
>>
>
>


 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

Thanks for the right way you showed us!
"Jeremy Darling" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
Look in borland.public.attachments I have placed a simple sample application
their that shows everything you need to know and does it with jpeg's.
Note though that properly the read and buffer swap should really be done
in a thread. I have done it in the VCL thread just to keep things simple.
The key really is the ControlStyle setup :).

Jeremy

"Gianluca" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Hi,
>first of all thanks for the support.
>
>At the moment we are doing something like the following code.
>Please could you explain us what do you mean with:
>1. to use a double buffer
>2. move the canvas handles to perform faster refreshes
>
>Thanks in advance
>Gianluca
>
>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>* *}
>procedure TForm1.GetImage(pixURL: String);
>var
>ImageStream: TMemoryStream;
>HTTP: TIdHTTP;
>begin
>ImageStream := TMemoryStream.Create;
>HTTP := TIdHTTP.Create(Self);
>HTTP.RecvBufferSize := 99999;
>try
>HTTP.Get(pixURL, ImageStream);
>ImageStream.Position := 0;
>try
>mJPEG.LoadFromStream(ImageStream);
>finally
>PaintBox1.Invalidate;
>end;
>finally
>ImageStream.Free;
>HTTP.Free;
>end;
>end;
>
>{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>* *}
>procedure TForm1.PaintBox1Paint(Sender: TObject);
>var
>lPaintBox: TPaintbox;
>begin
>lPaintBox:= Sender as TPaintbox;
>if Assigned( mJPEG ) then begin
>lPaintBox.Canvas.Draw(0, 0, mJPEG);
>end;
>
>
>
>
>
>
>"Jeremy Darling" <XXXX@XXXXX.COM>ha scritto nel messaggio
>news:437cc79e$XXXX@XXXXX.COM...
>>TPaintBox will only gain you speed not flicker reduction. For flicker
>>reduction you need Double Buffering.
>>
>>Basically create a TJPEGImage, load your file, and then perform the draw
>>to the paintboxes canvas or move the canvas handles to perform faster
>>refreshes.
>>
>>Jeremy
>>
>>"Gianluca" <XXXX@XXXXX.COM>writes
>>news:XXXX@XXXXX.COM...
>>>Hello,
>>>
>>>to prevent flickering we would like to use a TPaintBox instead of a
>>>TImage.
>>>The image we would like use comes from a web Server and it is a JPEG.
>>>We need to update the image every 300/500ms.
>>>
>>>Any help will be very precious..
>>>
>>>Thanks in advance,
>>>Gianluca
>>>
>>
>>
>
>


 

Re:how can I repaint every half second a TPaintBox with a JPEG from a Web Server?

Add a TTimer and set it to 300 or 500 and draw from within the timer event.
Or you could use the Application.OnIdle event for much smaller times.
"Nicholas Sherlock" <XXXX@XXXXX.COM>writes
Quote
Gianluca writes:
>to prevent flickering we would like to use a TPaintBox instead of a
>TImage.
>The image we would like use comes from a web Server and it is a JPEG.
>We need to update the image every 300/500ms.

One frame every half second would really be pushing it for most
combinations of image size and bandwidth that I can think of. Why not use
a video stream?

Cheers,
Nicholas Sherlock