-1

I'm using Borland C++Builder 6.

I would like to use the TImage component and just fill its content in a specific color (assume, black) - how can I do that?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
user687459
  • 143
  • 5
  • 17

1 Answers1

0

be more specific your text is a bit vague

Sorry I do not use TImage component but its high likely your TImage has Canvas so you can use GDI try something like:

img->Canvas->Brush->Color=clBlack;
img->Canvas->Brush->Style=bsSolid;
img->Canvas->FillRect(TRect(0,0,img->Width,img->Height)); 
  • where img is your TImage component name
  • there may be issues with Update similar to TPanintbox
  • so if you got flicker call img->Update(); or img->Refresh/Repaint... before this or move the rendering to different event like img->OnPaint ...
  • also you can use ClientWidth,ClientHeight if TImage has them (not all components does)
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Thanks you for you support! – user687459 Aug 20 '15 at 13:00
  • The `TImage::Canvas` property is only valid when the `TImage` is holding a `TBitmap` graphic. That is what you would actually be drawing on, as `TImage::Canvas` simply returns the `TImage::Picture::Bitmap::Canvas` pointer. If all you want to do is display a square/rectangle in a single color, you could assign a 1x1 pixel `TBitmap` to the `TImage`, making sure the `TImage::Stretch` property is set to true. Otherwise, use a `TPaintBox` instead and just `FillRect()` the `TPaintBox::Canvas` in the `TPaintBox::OnPaint` event. – Remy Lebeau Dec 09 '15 at 01:09