Forum > Graphics

Text to images Generator (Console app generating bitmaps with text)

<< < (2/17) > >>

Thank you I got error near declaration of bmp and first use of type TRect .

unit2.pas(40,12) Fatal: Syntax error, ";" expected but "identifier BMP" found

I don't see whats wrong

Lazarus 2.2.6

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit unit2; {$mode ObjFPC}{$H+} interface uses  Classes, SysUtils, Forms, Controls,  Graphics, Dialogs, StdCtrls,  Types, LCLType, LCLIntf; type   { TForm2 }   TForm2 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private   public   end; var  Form2: TForm2; implementation {$R *.lfm} { TForm2 } procedure TForm2.Button1Click(Sender: TObject);  const MARGIN = 3;  const TXT = 'A word';var  bmp: TBitmap;  ext: TSize;  R: TRect;begin  bmp := TBitmap.Create;  try    // Set the font and measure the text size    bmp.Canvas.Font.Name := 'Arial';    bmp.Canvas.Font.Size := 24;    bmp.Canvas.Font.Color := clRed;    bmp.Canvas.Font.Style := [fsItalic];    R.TopLeft := Point(0, 0);    R.BottomRight := TPoint(bmp.Canvas.TextExtent(TXT));    // Set the size of the bitmap (= text size + margin)    bmp.SetSize(R.Right + 2*MARGIN, R.Bottom + 2*MARGIN);    // Paint the bitmap's background color    bmp.Canvas.Brush.Color := clWhite;    bmp.Canvas.FillRect(0, 0, bmp.Width, bmp.Height);    // Draw the text    bmp.Canvas.TextOut(MARGIN, MARGIN, TXT);    // Save bitmap to file    bmp.SaveToFile('A_Word.bmp');  finally    bmp.Free;  end;end; end. 

I don't know - the code is compiling for me... If it still is not working pack the .pas, .lfm, .lpi and .lpr files into a common zip and upload that here ("Attachments and other options") so that I can test the entire project.

I'll try the code when I will be on Windows, maybe it will compile from there. Thank you for afford.

The code is not specific for Windows, it should compile under other operating systems, too.

Thank you. I have tested it on Windows and no problem. The only problem what I had because I am a newbie using Lazarus, that I have added the unit to already existing project because the old project was opened and I did not close it. It seem that next time I must close the project from Project menu and then select New Project from the same menu...

So I will start linux now because I need to download the fonts which I cannot download on the Windows XP and I can try again to compile it on Linux Mint - Lazarus... and I will ask chatGPT to do the rest of job.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version