[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppClxGraphics
RGB is a macro. TPaintBox gets updated after every change in pixel. This makes it slow.
The function ScanLine returns a void pointer, therefore it needs to be cast to an unsigned char pointer. Note that red, green and blue are reversed in the obtained pointer.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppClxGraphics
(C++ CLX) Graphics
Graphics in the CLX can be accomplished using a TPaintBox or a TImage component. The first is easier, yet slower and gives flicker.Example using TPaintBox
const unsigned int maxx = PaintBox1->Width;
const unsigned int maxy = PaintBox1->Height;
for (unsigned int y = 0; y < maxy; ++y)
{
for (unsigned int x = 0; x < maxx; ++x)
{
PaintBox1->Canvas->Pixels[x][y] = RGB(x,y,x+y);
} //Next y
} //Next x
RGB is a macro. TPaintBox gets updated after every change in pixel. This makes it slow.
Example using TImage
Put a TImage on the Form called Image1 (this is the default name). Set the Picture Property to a 32 bitmap (created in for example MS Paint).
assert(Image1->Picture->Bitmap->PixelFormat == pf32bit); //Assume a 32 bitmap
const unsigned int maxx = Image1->Picture->Bitmap->Width;
const unsigned int maxy = Image1->Picture->Bitmap->Height;
for (unsigned int y = 0; y != maxy; ++y)
{
unsigned char * const myLine
= static_cast<unsigned char* const>(
Image1->Picture->Bitmap->ScanLine[y]); //CLX is not const correct. Grumble, grumble...
for (unsigned int x = 0; x != maxx; ++x)
{
//myLine[x*4+3] = (x+y)%256; //Alpha blending?
myLine[x*4+2] = (x )%256; //Red
myLine[x*4+1] = ( y)%256; //Green
myLine[x*4+0] = (x+y)%256; //Blue
}
}
//Add these lines below if you want to StretchDraw it on your Form
//assert(Image1->Visible == false);
//this->Canvas->StretchDraw(this->ClientRect, Image1->Picture->Graphic); //Assumes you work in a Form's method
The function ScanLine returns a void pointer, therefore it needs to be cast to an unsigned char pointer. Note that red, green and blue are reversed in the obtained pointer.
Example using double-buffering
Work in progress...'Graphics' links
- general
- C
- C++
- C++ Builder
- C++ VCL
- Pascal CLX
- Pascal VCL
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
