[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CPpVclTImage
Examples:
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]
CPpVclTImage
(C++ VCL) TImage
Component for doing graphics.
//Forward declaration
namespace Extctrls { class TImage; }
- include <system.hpp>
Examples:
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), mImage(new TImage(0)) { assert(FileExists("1x1.bmp")) mImage->Picture->LoadFromFile("1x1.bmp"); //Loading a bitmap mImage->AutoSize = true; //Do not forget this one! mImage->Picture->Bitmap->Width = random(256); //Random width mImage->Picture->Bitmap->Height = random(256); //Random height } void draw() const { const int maxy = mImage->Picture->Bitmap->Height; const int maxx = mImage->Picture->Bitmap->Width; for (int y=0; y!=maxy; ++y) { unsigned char * pLine = static_cast<unsigned char *>(mImage->Picture->Bitmap->ScanLine[y]); for (int x=0; x!=maxx; ++x) { pLine[x*3+0]= 0; //Blue pLine[x*3+1]= 0; //Green pLine[x*3+2]= random(256); //Red } } mCanvas->Draw(0,0,mImage->Picture->Graphic); //Drawing it } private: TCanvas * mCanvas; std::auto_ptr<TImage> mImage; };
- include <cassert>
- include <memory>
- include <ExtCtrls.hpp>
Code links
'TImage' links
- C++ CLX
- C++ VCL
- C++ Builder
- Pascal CLX
- Pascal VCL
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
