[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppClxTImage
Below is an example of a class that dynamically generates a bitmap TImage and draws it to a TCanvas it is initialized on.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
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.
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; };
- include <memory>
- include <ExtCtrls.hpp>
Code links
'TImage' links
- C++ VCL
- C++ Builder
- Pascal CLX
- Pascal VCL
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
