Board index » cppbuilder » Exchange TImage from TImageList without flickering?
Michael
![]() CBuilder Developer |
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 |