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

(C++ VCL) TImage

Component for doing graphics.

//Forward declaration
namespace Extctrls { class TImage; }
  1. 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.

  1. include <cassert>
  2. include <memory>
  3. include <ExtCtrls.hpp>
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; };


Code links

'TImage' links



last edited (December 18, 2006) by bilderbikkel, Number of views: 5169, Current Rev: 10 (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.