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 in ScrollBox; resize speed prob at wsMaximize

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics
View previous topic :: View next topic  
Author Message
Klaus Hast
Guest





PostPosted: Wed Jul 12, 2006 2:37 am    Post subject: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote



Hi dear experts,

I have (D4/Win98 or D6PE/W2K) a TImage on a ScrollBox (ScrollBox
DoubleBuffered:=True)
presenting a Bitmap received from somewhere kept in a FBitmap variable,
where mostly the TImage is alClient aligned to the Scrollbox.
The bitmap's load time and normal resize actions are ok.
But at doubleclick on the caption bar (-> wsMaximize) i have a noticeable
speed delay
compared eg. to similar C-Applications (when maximizing the window).
---
Without doublebuffer the speed is ok, but i get flicker.
With doublebuffer no flicker, but the speed at maximize decreases
noticeably.
Some tests on FBitmap's fast stretch operations by hand did not have better
results.
--
Questions to the experts: any proposals to improve the performance
of maximize actions on a TImage parented by a ScrollBox?
Any hack-arounds the StretchDraw-API within the TImage Bitmap draw
or is it the fastest method we can have?

Many thanks for advice in advance,
Klaus
PS: replacing the scrollbox by a paintbox or panel does not have better
results.
Back to top
Finn Tolderlund
Guest





PostPosted: Wed Jul 12, 2006 2:44 am    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote



"Klaus Hast" <khast (AT) arcor (DOT) de> skrev i en meddelelse
news:44b41a58$1 (AT) newsgroups (DOT) borland.com...
Quote:
Questions to the experts: any proposals to improve the performance
of maximize actions on a TImage parented by a ScrollBox?
Any hack-arounds the StretchDraw-API within the TImage Bitmap draw
or is it the fastest method we can have?

How large is the bitmap?
Make sure that it's no larger than the screen size.
If it is larger, resize it down before putting it into the TImage.
That might improve performance.
--
Finn Tolderlund
http://www.tolderlund.eu/delphi/
Back to top
Klaus Hast
Guest





PostPosted: Wed Jul 12, 2006 2:51 am    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote



Hi (and many thanks for reply!),

Before the TImage sees the the FBitmap, it is already resized
so that it does not exceed the boundaries of the screen.
So the issue is not related to a bitmap which is too large regarding width
or height.

Best Regards!
Koaus

Quote:
How large is the bitmap?
Make sure that it's no larger than the screen size.
If it is larger, resize it down before putting it into the TImage.
That might improve performance.
Back to top
C-H
Guest





PostPosted: Wed Jul 12, 2006 3:05 pm    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

"Klaus Hast" <khast (AT) arcor (DOT) de> wrote:
Quote:
any proposals to improve the performance
of maximize actions on a TImage parented by a ScrollBox?


A trick I've used to kill flicker without having to set DoubleBuffered
to true is to trap the WM_ERASEBKGND message sent to the control on which
the Image or Painbox is placed, and tell the control not to erase its
background if it doesn't have to (transparent pictures are problematic).
If you have other things on the ScrollBox the best solution would probably
be to make a TPanel descendant and place the image on that. Align the Image
to Client.

You could try installing a component that looks something like this:
-----------------------
unit PanelFF;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, Forms, Graphics;

type
TPanelFF = class(TPanel)
private
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
public
constructor Create(AOwner: TComponent); override;
property EraseBG: Boolean read FEraseBg write FEraseBg;
end;

procedure Register;

implementation

constructor TPanelFF.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEraseBg := True;
end;

procedure TPanelFF.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
begin
if not EraseBg then
Msg.Result := 1 //don't erase bg
else
inherited;
end;

procedure Register;
begin
RegisterComponents('Samples', [TPanelFF]);
end;

end.
----------------------
In your app you can then determine if you wan't to erase or not.
For instance:

if MyPictureIsTransparent then
PanelFF1.EraseBg := True
else
PanelFF1.EraseBg := False;

/C-H
Back to top
Klaus Hast
Guest





PostPosted: Wed Jul 12, 2006 9:57 pm    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

Hi C-H,

i already used the suppression of the WM_ERASEBKGND message,
without good results, but however you gave me the good idea ...
in fact i need to take care that this trap has to be applied
on the parent of the image, so the scrollbox ... So i created a
TScrollBox descendant and applied it here ... and that looks promising!
---
However that leads to the subsequent question how to repaint the
remaining part of the scrollbox which is not covered by the image.
---
What i mean is: regarding the size of the image which is
proportionally stretched (keeping its aspect ratio) the
resized scrollbox is not fully filled by the proportinally resized
and centered image (parts of the top/bottom resp. left/right would
need to be repainted using the background color by hand).
---
So, how to detect and repaint the regions of the scrollbox
which are not fully covered by the image?
(repaint scrollbox minus DestRect of the Image)

Many thanks again,
Klaus



Quote:
A trick I've used to kill flicker without having to set DoubleBuffered
to true is to trap the WM_ERASEBKGND message sent to the control on which
the Image or Painbox is placed, and tell the control not to erase its
background if it doesn't have to (transparent pictures are problematic).
If you have other things on the ScrollBox the best solution would probably
be to make a TPanel descendant and place the image on that. Align the
Image
to Client.
Back to top
Peter Below (TeamB)
Guest





PostPosted: Wed Jul 12, 2006 11:31 pm    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

Klaus Hast wrote:

Quote:
Hi dear experts,

I have (D4/Win98 or D6PE/W2K) a TImage on a ScrollBox (ScrollBox
DoubleBuffered:=True)
presenting a Bitmap received from somewhere kept in a FBitmap
variable, where mostly the TImage is alClient aligned to the
Scrollbox. The bitmap's load time and normal resize actions are ok.
But at doubleclick on the caption bar (-> wsMaximize) i have a
noticeable speed delay
compared eg. to similar C-Applications (when maximizing the window).
---
Without doublebuffer the speed is ok, but i get flicker.

Ditch the image, use a TPaintbox instead and paint the bitmap in its
OnPaint event. This way you control whether the background gets erased
or not. Doublebuffering is no longer necessary.



--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Klaus Hast
Guest





PostPosted: Thu Jul 13, 2006 12:24 am    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

Peter Below (TeamB) <none> schrieb in im Newsbeitrag:
xn0eon85z19bsg002 (AT) newsgroups (DOT) borland.com...
Quote:
Ditch the image, use a TPaintbox instead and paint the bitmap in its
OnPaint event. This way you control whether the background gets erased
or not. Doublebuffering is no longer necessary.

Hello Peter,

First, kind thanks for your quick reply!
Compared with the paintbox approach do you see any disadvantages
when using the (non-doublebufferd) scrollbox approach as described
in my reply to C-H within this thread ?
(Descendant of TScrollBox [for to suppress wm_erasebkgnd];
TImage herein -> for to have all scrolling and proportional
resizing (StretchDraw) capabilities without reinventing the wheel).
Is it quite as good in your eyes?
If yes: only remaining question: how to detect and repaint the
regions of the scrollbox which are not fully covered by a
proportionally stretched, and then centered, image (when aspect
ratio of the image <> aspect ratio of the scrollbox) ?
If no: why?

Many thanks,
Klaus
Back to top
C-H
Guest





PostPosted: Thu Jul 13, 2006 2:05 am    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

"Klaus Hast" <khast (AT) arcor (DOT) de> wrote:
Quote:
Hi C-H,

---
However that leads to the subsequent question how to repaint the
remaining part of the scrollbox which is not covered by the image.
---
So, how to detect and repaint the regions of the scrollbox
which are not fully covered by the image?
(repaint scrollbox minus DestRect of the Image)

I understand your problem, but that approach is hard to pull
through. You will probably end up getting flicker again from
large areas having to be repainted separately. My advise would be
to try placing the Image on a Panel and do the sizing operations
on the Panel instead of on the Image (keep the Image aligned to
client and set streched to true).

In my experience trapping the WM_ERASEBKGND message is the only way
to control flicker in certain situations. Peter's suggestion is not enough.

/C-H
Back to top
C-H
Guest





PostPosted: Thu Jul 13, 2006 2:39 pm    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

"C-H" <blabla (AT) NO_SPAM (DOT) com> wrote:
Quote:

My advise would be to try placing the Image on a Panel and do the sizing operations
on the Panel instead of on the Image.


Scrolling performance may suffer though. As we don't know what
your app is doing and how you want your picture presented it's
difficult to come up with relevant solutions. We're also in a tricky
trial-and-error territory here. The question is, why are you getting flicker
in the first place? Are you moving the Image to keep it centered at resizing?
If so I have no good solution to offer, sorry.

/C-H
Back to top
Peter Below (TeamB)
Guest





PostPosted: Thu Jul 13, 2006 11:44 pm    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

Klaus Hast wrote:

Quote:
Compared with the paintbox approach do you see any disadvantages
when using the (non-doublebufferd) scrollbox approach as described
in my reply to C-H within this thread ?
(Descendant of TScrollBox [for to suppress wm_erasebkgnd];
TImage herein -> for to have all scrolling and proportional
resizing (StretchDraw) capabilities without reinventing the wheel).
Is it quite as good in your eyes?

It could certainly be made to work.

Quote:
If yes: only remaining question: how to detect and repaint the
regions of the scrollbox which are not fully covered by a
proportionally stretched, and then centered, image (when aspect
ratio of the image <> aspect ratio of the scrollbox) ?

Build a region from the parts of the scrollboxes visible area that are
covered by other controls. Save the state of the canvas.handle
(SaveDC), select the region as clipping region into the canvas.handle
(SelectClipRgn), then do the standard background fill for the
scrollbox. Finally restore the canvas.handle state (RestoreDC).

You can also directly paint the bitmap at this point, no need or use
for a paintbox or timage.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Klaus Hast
Guest





PostPosted: Fri Jul 14, 2006 1:20 am    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

Hello Peter,

thank you for all those responses!
I try to test with this proposal.
Meanwhile i got the following construct to work too quite sufficiently (at
least better than before):

* Form
(for to keep scrolling capabilities:)
* Non-doublebuffered Scrollbox descendant which supresses erase_background
(for to keep proportional scaling and centering capabilities:)
* A TImage clone (base on TGrapiccontrol) which does a corrective action
before the StretchDraw:
if DestRect.top > 0 then
canvas.FillRect(Rect(0, 0, width, DestRect.top-1));
if DestRect.bottom < height then
canvas.FillRect(Rect(0, DestRect.bottom+1, width, height));
if DestRect.left > 0 then
canvas.FillRect(Rect(0, 0, DestRect.left, height));
if DestRect.right < width then
canvas.FillRect(Rect(DestRect.right+1, 0, width, height));
canvas.stretchdraw(DestRect, picture.graphic);

Is that be ok in your eyes, basically, or simply a bad hack?

Best Regards,
Klaus
Back to top
Peter Below (TeamB)
Guest





PostPosted: Fri Jul 14, 2006 11:43 pm    Post subject: Re: TImage in ScrollBox; resize speed prob at wsMaximize Reply with quote

Klaus Hast wrote:

Quote:
Hello Peter,

thank you for all those responses!
I try to test with this proposal.
Meanwhile i got the following construct to work too quite
sufficiently (at least better than before):

-snip-

Is that be ok in your eyes, basically, or simply a bad hack?

That's no hack, that's a tweak <g>. And a decent one, IMO.


--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Graphics 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.