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 

Painting on a PaintBox from a thread question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Nicolas VanOrton
Guest





PostPosted: Wed Apr 13, 2005 6:40 am    Post subject: Painting on a PaintBox from a thread question Reply with quote



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
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (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.