Link to home
Start Free TrialLog in
Avatar of szafran
szafran

asked on

Writing text/Drawing lines on a TBitmap

Hi

I have a proggy that generates this picture: http://members.lycos.co.uk/szafran/uptime.gif using GetFormImage. And i want to write the text and draw the lines on a TBitmap without having to use a form for it. Can anyone try to write me a code that will draw me at least the grey box and one of the black boxes including the text in them ?

Thanks in advance for all your help with this.
Szafran
Avatar of mokule
mokule
Flag of Poland image

Not exactly, but all fetures included

procedure TForm1.Button1Click(Sender: TObject);
var
  bmp:TBitmap;
begin
  bmp := GetFormImage;
  with bmp.Canvas do
    begin
    Brush.Color := clYellow;
    FillRect(Rect(5,5,200,200));
    MoveTo(10,10);
    LineTo(100,10);
    TextOut(30,30,'test');
    end;
  bmp.SaveToFile('d:\test.bmp');
end;
or if You want to draw on a created bitmap

procedure TForm1.Button2Click(Sender: TObject);
var
  bmp:TBitmap;
begin
  bmp := TBitmap.Create;
  bmp.Width := 210;
  bmp.Height := 210;
  bmp.PixelFormat := pf24bit;
  with bmp.Canvas do
    begin
    Brush.Color := clGray;
    FillRect(Rect(5,5,200,200));
    Rectangle(Rect(8,8,197,197));
    MoveTo(13,13);
    LineTo(192,13);
    TextOut(20,20,'test');
    end;
  bmp.SaveToFile('d:\test.bmp');
  bmp.Free;
end;
Avatar of szafran
szafran

ASKER

and how ca i get the length of the written text in pixels ?? because the lines/boxes need to be aligned to the text size.
Avatar of szafran

ASKER

and also, after finishing the drawing i'll need to crop the left side of the bmp, how can i do it ?
Avatar of szafran

ASKER

and also... how to change the font and size of it used to write on the bitmap ?
- bmp.Canvas.TextWidth('jakis tekst');

- crop? You mean what exactly?

-
bmp.Canvas.Font.Name := 'Arial'
bmp.Canvas.Font.Size := 36;
Avatar of szafran

ASKER

about the crop i mean that i'll create a bmp that is for eg 1000px width and after doing all of the writing/drawing i'll need to chenge it's width to be about 2px wider than the drawings/text on it.


p.s. mokule r u polish ??
If You want to cut right or bottom it's easy.
Just
  bmp.Width := SomeNewWidth
  bmp.Height := SomeNewHeight;

PS. sure. surprised?
Avatar of szafran

ASKER

a little surprised ;)
if only i could write here in polish it would be easier for you to understand what i'm trying to do, but for now i have to see if the code that you gave is everything that i need to manually draw the picture that i need.
ASKER CERTIFIED SOLUTION
Avatar of mokule
mokule
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of szafran

ASKER

thanks for your help.
you're welcome