Nicolas VanOrton Guest
|
Posted: Wed Apr 13, 2005 6:40 am Post subject: Painting on a PaintBox from a thread question |
|
|
Hi all,
I'm painting the images I'm receiving from a TIdTCPServer onto a
PaintBox (pBox1). My code is the following (Bmp is a Graphics::TBitmap):
// As known, ServerExecute is running in its own connection thread...
void __fastcall TMainForm::ServerExecute(TIdPeerThread *AThread)
{
unsigned char Buffer[3*IMG_WIDTH*IMG_HEIGHT];
AThread->Connection->ReadBuffer(Buffer, 3*IMG_WIDTH*IMG_HEIGHT);
int g=0;
BYTE red,green,blue;
Bmp->Canvas->Lock();
for (int i=0; i<IMG_HEIGHT; i++)
for (int j=0; j
{
green = Buffer[g++];
blue = Buffer[g++];
red = Buffer[g++];
Bmp->Canvas->Pixels[j][i] = (TColor)RGB(red, green, blue);
}
Bmp->Canvas->Unlock();
AThread->Synchronize(RepaintPaintBox);
}
void __fastcall TMainForm::RepaintPaintBox()
{
pBox1->Repaint();
}
void __fastcall TMainForm::pBox1Paint(TObject *Sender)
{
// pBox1->Canvas->Lock();
// Bmp->Canvas->Lock();
pBox1->Canvas->Draw(0,0,Bmp);
// Bmp->Canvas->Unlock();
// pBox1->Canvas->Unlock();
}
I am wondering whether or not I actually have to lock PaintBox's
and Bitmap's Canvases in the OnPaint (pBox1Paint) event...
I got a bit confused.
- pBox1->Canvas is actually edited inside pBox1Paint from a thread,
but this is done in a Synchronized method...
- Bmp->Canvas is not actually edited in there...
Any thoughts would be welcome...
Thanks!
Nicolas
|
|