[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppClxTImage

(C++ CLX) TImage

Component for doing graphics.

  •  ?Example of low-level graphics

Creating a bitmap TImage dynamically

The problem of dyncamically creating a bitmap TImage is that I can only set it to a bitmap by loading a bitmap image!

Below is an example of a class that dynamically generates a bitmap TImage and draws it to a TCanvas it is initialized on.

  1. include <memory>
  2. include <ExtCtrls.hpp>
class NewImage { public: NewImage(TCanvas * canvas) : mCanvas(canvas) {} void draw() const { std::auto_ptr<TImage> pImage(new TImage(0)); pImage->Picture->LoadFromFile("32x32.bmp"); //Loading a bitmap pImage->AutoSize = true; //Do not forget this one! pImage->Picture->Bitmap->Width = random(256); //Random width pImage->Picture->Bitmap->Height = random(256); //Random height for (int y=0; y != pImage->Picture->Bitmap->Height; ++y) { unsigned char * pLine=static_cast<unsigned char *>(pImage->Picture->Bitmap->ScanLine[y]); for (int x=0; x<pImage->Picture->Bitmap->Width; ++x) { pLine[x*3+0]= 0; //Blue pLine[x*3+1]= 0; //Green pLine[x*3+2]= random(256); //Red } } mCanvas->Draw(0,0,pImage->Picture->Graphic); //Drawing it } private: TCanvas * mCanvas; };


Code links

'TImage' links



last edited (November 11, 2006) by bilderbikkel, Number of views: 1577, Current Rev: 3 (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.