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
Delphi

Avatar of undefined
Last Comment
mokule

8/22/2022 - Mon
mokule

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;
mokule

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;
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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
szafran

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

ASKER
and also... how to change the font and size of it used to write on the bitmap ?
mokule

- bmp.Canvas.TextWidth('jakis tekst');

- crop? You mean what exactly?

-
bmp.Canvas.Font.Name := 'Arial'
bmp.Canvas.Font.Size := 36;
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
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 ??
mokule

If You want to cut right or bottom it's easy.
Just
  bmp.Width := SomeNewWidth
  bmp.Height := SomeNewHeight;

PS. sure. surprised?
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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
mokule

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
szafran

ASKER
thanks for your help.
mokule

you're welcome