: You do not necessarily need to use a TImage. The advantage of
: creating a TBitmap object directly is that the GUI doesn't need to
: be used. This can especially create a speed optimalization if the
: image gets changed.
Hi zibadian,
Thanks for your reply! You are right and I wish I could do it the right way. But in C++ Builder I can't get this right way to work! I posted multiple times about this subject already. The problem lies in assigning the TBitmap* to the TImage*. If you can get the function 'AssignBitmapTImage' below working, I would have bought you a beer if you would live somewhere near

. No hard feelings though, if you have higher priorities...
//Needed on the Form:
//* A TButton called Button1
//* A TImage called Image1
void DoCoolEffect(Graphics::TBitmap * const bitmap)
{
const int maxx = bitmap->Width;
const int maxy = bitmap->Height;
for (int y = 0; y != maxy; ++y)
{
unsigned char * const myLine = static_cast<unsigned char*>(bitmap->ScanLine[y]);
for (int x = 0; x != maxx; ++x)
{
myLine[x*3+2] = (x+0) % 256; //Red
myLine[x*3+1] = (y+0) % 256; //Green
myLine[x*3+0] = (x+y) % 256; //Blue
}
}
}
//---------------------------------------------------------------------------
void AssignBitmapToImage(Graphics::TBitmap * const bitmap,TImage * const image)
{
image->Width = bitmap->Width;
image->Height = bitmap->Height;
//Does not work:
//image->Picture->Assign(bitmap);
image->Picture->Bitmap = bitmap;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
const int maxx = 256;
const int maxy = 256;
Graphics::TBitmap * bitmap = new Graphics::TBitmap;
bitmap->Width = maxx;
bitmap->Height = maxy;
DoCoolEffect(bitmap);
AssignBitmapToImage(bitmap,Image1);
assert(bitmap->Width == Image1->Width);
assert(bitmap->Height == Image1->Height);
#ifndef NDEBUG
for (int y=0; y!=maxy; ++y)
{
for (int x=0; x!=maxx; ++x)
{
assert(bitmap->Canvas->Pixels[0][0] == Image1->Canvas->Pixels[0][0]);
}
}
#endif
Image1->Visible = true;
Image1->Refresh();
//Delete necessary???
}
//---------------------------------------------------------------------------
The result will be a white square as if the GUI does not know what happened 'behind the scenes'...
See ya,
bilderbikkel