[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
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



last edited (July 3, 2007) by bilderbikkel, Number of views: 2158, Current Rev: 5 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.