Board index » cppbuilder » Exchange TImage from TImageList without flickering?

Exchange TImage from TImageList without flickering?


2005-08-07 08:29:33 PM
cppbuilder97
Hi group,
I'm trying to exchange an image to a TImage (imButton) from a TImageList
(imgListButtons).
The image is changed on the mouseover event on the TImage imgButton given
X,Y coordinates colors from a lookup picture imgLookup of identical size to
imgButton.
If the lookup picture is white, image 0 is used.
If the lookup picture is red, image 1 is used, and so forth...
The image is only exchanged if the image number is different from the
currently displayed image.
The below code does the job, but the image exchanges flicker tremendously.
Please advice - thanks! :-D
Best regards
Michael, Denmark
CODE BEGINS
void __fastcall TForm1::imgButtonMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
TColor c = imgLookup->Canvas->Pixels[X][Y];
int n = -1;
switch(c) {
case clWhite: n = 0; break;
case clRed: n = 1; break;
case clBlue: n = 2; break;
case clGreen: n = 3; break;
default: n = -1; break;
}
if(n>=0) {
exchangeImage(imgButton, imgListButtons, n);
}
}
void __fastcall TForm1::exchangeImage(TImage *ptrImg, TImageList
*ptrImglist, unsigned int indx)
{
/*
**Only change the image if different from currently
** displayed image (remember value in the Tag)
*/
if(ptrImg->Tag == indx) return;
ptrImg->Tag = indx;
ptrImglist->GetBitmap(indx, ptrImg->Picture->Bitmap);
ptrImg->Invalidate();
}
CODE ENDS
 
 

Re:Exchange TImage from TImageList without flickering?

"Michael" < XXXX@XXXXX.COM >wrote in message
Quote
ptrImglist->GetBitmap(indx, ptrImg->Picture->Bitmap);
ptrImg->Invalidate();
You don't need to call Invalidate(). When the Bitmap is changed, the TImage
automatically Invalidate()'s itself immediately.
Gambit
 

Re:Exchange TImage from TImageList without flickering?

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >skrev i en meddelelse
Quote

"Michael" < XXXX@XXXXX.COM >wrote in message
news:42f5feb2$ XXXX@XXXXX.COM ...

>ptrImglist->GetBitmap(indx, ptrImg->Picture->Bitmap);
>ptrImg->Invalidate();

You don't need to call Invalidate(). When the Bitmap is changed, the
TImage
automatically Invalidate()'s itself immediately.

Gambit
I have tried with and without the Invalidate. The image exchanges still
flicker.
I suspect that the GetBitmap call sets the image picture pointer to NULL (or
something similar), causing the image area to get redrawn by first wiping
the entire image area black (background clear), and then when the new bitmap
is exchanged in, it is redrawn scanline by scanline. All in all resulting in
intolerable flickering.
I would like to be able to halt all updates to the user interface while the
image is being updated - i.e.:
HaltGUIUpdates();
ptrImglist->GetBitmap(indx, ptrImg->Picture->Bitmap);
ResumeGUIUpdates();
...such that the image is completly drawn before it is being updated. Is
this in any way possible?
Thanks for your time!
Best regards
Michael, Denmark
 

{smallsort}

Re:Exchange TImage from TImageList without flickering?

"Michael" < XXXX@XXXXX.COM >wrote in message
Quote
I suspect that the GetBitmap call sets the image picture
pointer to NULL
No, it does not. GetBitmap() has no concept of the Picture at all. It only
knows about the TBitmap that is passed in to it. The TImageList draws
directly onto that TBitmap after resizing it first.
Your flickering might be caused by the Bitmap's Width and Height properties
being changed separately by GetBitmap(). Each change will cause the TImage
to draw itself. Try passing a temporary TBitmap to GetBitmap() and then
Assign() the temporary TBitmap to the main TBitmap afterwards. This way,
the TImage is only notified once of any changes instead of multiple times.
For example:
void __fastcall TForm1::exchangeImage(TImage *ptrImg, TImageList
*ptrImglist, unsigned int indx)
{
if( ptrImg->Tag != indx )
{
ptrImg->Tag = indx;
Graphics::TBitmap *bmp = new Graphics::TBitmap;
try
{
ptrImglist->GetBitmap(indx, bmp);
ptrImg->Picture->Bitmap->Assign(bmp);
}
__finally {
delete bmp;
}
}
}
Quote
causing the image area to get redrawn by first wiping the entire
image area black (background clear), and then when the new
bitmap is exchanged in, it is redrawn scanline by scanline.
Nope. That is not how it works.
Quote
I would like to be able to halt all updates to the user interface
while the image is being updated - i.e.:
Look at the WM_SETREDRAW message.
Gambit
 

Re:Exchange TImage from TImageList without flickering?

Hi, all,
I'd like to join this discussion because I encountered the same problem. I
suspect it maybe caused by TImage's bugs in BCB6.
I've developed an APP that loading a picture in TImage component and draw
some lines and some shapes - circle, rectangle etc on it. In BCB4, it worked
ok, have no any flickering problem. Recently I moved the same code to BCB6,
once I drew some thing on it, it flickered tremendously.
Another example code provided by BCB also can testify it.
Open and compile doodle.bpr in \CBuilder4\Examples\Apps\Doodle in BCB4 and
run it, fill some color first, and draw line or any shape on it, it works
ok.
Open and compile doodle.bpr in \CBuilder6\Examples\Apps\Doodle in BCB6 and
run it, do same thing, you will see tremendous flicker.
Is any bugs of TImage in BCB6?
Shan
 

Re:Exchange TImage from TImageList without flickering?

Liu Shan wrote:
Quote
I've developed an APP that loading a picture in TImage component and draw
some lines and some shapes - circle, rectangle etc on it. In BCB4, it worked
ok, have no any flickering problem. Recently I moved the same code to BCB6,
once I drew some thing on it, it flickered tremendously.
Try setting the Stretch property to true and see if it helps. I know
there was a flickering issue with BCB6 when it was released but I don't
know if this problem was addressed in one of the patches available.
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:Exchange TImage from TImageList without flickering?

Thanks Michel, it worked.
But it's a temporary solution, if APP wants fix image, it will cause another
problem. I'd like to wait for BCB6 new patch to dress this problem ASAP.
BTW, how to report bug to Borland?
Shan
"Michel Leunen" < XXXX@XXXXX.COM >wrote in message
Quote
Liu Shan wrote:

>I've developed an APP that loading a picture in TImage component and
draw
>some lines and some shapes - circle, rectangle etc on it. In BCB4, it
worked
>ok, have no any flickering problem. Recently I moved the same code to
BCB6,
>once I drew some thing on it, it flickered tremendously.

Try setting the Stretch property to true and see if it helps. I know
there was a flickering issue with BCB6 when it was released but I don't
know if this problem was addressed in one of the patches available.

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:Exchange TImage from TImageList without flickering?

Liu Shan wrote:
Quote
Thanks Michel, it worked.
But it's a temporary solution, if APP wants fix image, it will cause another
problem. I'd like to wait for BCB6 new patch to dress this problem ASAP.
Hmm, I'm not sure there will be another patch for BCB6 :-(
We are all looking forward to the next release.
Quote
BTW, how to report bug to Borland?
You have to go to Quality Central and report it there:
qc.borland.com/wc/qcmain.aspx
Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:Exchange TImage from TImageList without flickering?

Very Thanks.
Shan
"Michel Leunen" < XXXX@XXXXX.COM >wrote in message
Quote
Liu Shan wrote:
>Thanks Michel, it worked.
>But it's a temporary solution, if APP wants fix image, it will cause
another
>problem. I'd like to wait for BCB6 new patch to dress this problem ASAP.

Hmm, I'm not sure there will be another patch for BCB6 :-(
We are all looking forward to the next release.

>BTW, how to report bug to Borland?

You have to go to Quality Central and report it there:
qc.borland.com/wc/qcmain.aspx

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
www.leunen.com/
----------------------------------------
 

Re:Exchange TImage from TImageList without flickering?

if you want to draw your images without flicker, maybe DirectDraw can help
because it does so perfectly.
visit bcb-tools.com
our older v1.42 versions of the TDx_Draw_Library (DirectDraw components for
BCB) is FREE.
- darren
"Liu Shan" < XXXX@XXXXX.COM >wrote in message
Quote
Very Thanks.

Shan

"Michel Leunen" < XXXX@XXXXX.COM >wrote in message
news:4304d79f$ XXXX@XXXXX.COM ...
>Liu Shan wrote:
>>Thanks Michel, it worked.
>>But it's a temporary solution, if APP wants fix image, it will cause
another
>>problem. I'd like to wait for BCB6 new patch to dress this problem
ASAP.
>
>Hmm, I'm not sure there will be another patch for BCB6 :-(
>We are all looking forward to the next release.
>
>>BTW, how to report bug to Borland?
>
>You have to go to Quality Central and report it there:
>qc.borland.com/wc/qcmain.aspx
>
>Michel
>--
>----------------------------------------
>Michel Leunen
>mailto: see my homepage.
>C++Builder, BCC5.5.1 Web site:
>www.leunen.com/
>----------------------------------------