draw an image or a bitmap in memory and modify it in memory lazarus / 39-Graphics ---------------------------------------------------------------------- rabbit_dance · 2021-04-20 13:33 please describe how to draw an image or a bitmap in memory and modify it in memory and how to put it on the screen ---------------------------------------------------------------------- VTwin · 2021-04-20 13:40 Have a look here: https://wiki.lazarus.freepascal.org/Developing_with_Graphics ---------------------------------------------------------------------- rabbit_dance · 2021-04-20 13:54 thanks, but how to do so under console under such as linux? ---------------------------------------------------------------------- Handoko · 2021-04-20 14:32 Console?  Why do you need doing graphics in console mode? I haven't tried but if TBitmap can be used on console mode then there is no difference as doing it in GUI mode, just don't show it on the GUI form. Below is a demo drawing objects on TBitmap in memory (GUI mode), which with some modifications I believe can be used in console mode: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    btnShow: TButton;    btnCreate: TButton;    btnClear: TButton;    btnWhite: TButton;    btnCircle: TButton;    btnSquare: TButton;    procedure btnCircleClick(Sender: TObject);    procedure btnClearClick(Sender: TObject);    procedure btnCreateClick(Sender: TObject);    procedure btnShowClick(Sender: TObject);    procedure btnSquareClick(Sender: TObject);    procedure btnWhiteClick(Sender: TObject);    procedure FormCreate(Sender: TObject);  private    FBitmap: TBitmap;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  FBitmap := nil;end; procedure TForm1.btnCircleClick(Sender: TObject);const  D = 30;var  X, Y: Integer;begin  if not(Assigned(FBitmap)) then  begin    ShowMessage('Please create the bitmap first.');    Exit;  end;  X := Random(FBitmap.Width  - D);  Y := Random(FBitmap.Height - D);  FBitmap.Canvas.Brush.Color := Random($FFFFFF);  FBitmap.Canvas.Ellipse(X, Y, X+D, Y+D);end; procedure TForm1.btnClearClick(Sender: TObject);begin  if not(Assigned(FBitmap)) then  begin    ShowMessage('Please create the bitmap first.');    Exit;  end;  FBitmap.Canvas.Brush.Color := clBlack;  FBitmap.Canvas.Clear;end; procedure TForm1.btnShowClick(Sender: TObject);begin  if not(Assigned(FBitmap)) then  begin    ShowMessage('The bitmap has not created yet.');    Exit;  end;  Canvas.Draw(10, 10, FBitmap)end; procedure TForm1.btnSquareClick(Sender: TObject);const  S = 30;var  X, Y: Integer;begin  if not(Assigned(FBitmap)) then  begin    ShowMessage('Please create the bitmap first.');    Exit;  end;  X := Random(FBitmap.Width  - S);  Y := Random(FBitmap.Height - S);  FBitmap.Canvas.Brush.Color := Random($FFFFFF);  FBitmap.Canvas.Rectangle(X, Y, X+S, Y+S);end; procedure TForm1.btnWhiteClick(Sender: TObject);begin  if not(Assigned(FBitmap)) then  begin    ShowMessage('Please create the bitmap first.');    Exit;  end;  FBitmap.Canvas.Brush.Color := clWhite;  FBitmap.Canvas.Rectangle(0, 0, FBitmap.Width, FBitmap.Height);end; procedure TForm1.btnCreateClick(Sender: TObject);begin  if Assigned(FBitmap) then  begin    ShowMessage('The bitmap has been created.');    Exit;  end;  FBitmap := TBitmap.Create;  FBitmap.Height := 100;  FBitmap.Width  := 200;end; end. For your information, doing image using TCanvas is slow. If you want to develop a 'real' graphics program (maybe batch editing, watermarking, or resizing) you should use a 'better' graphics library. https://wiki.lazarus.freepascal.org/Graphics_libraries [edit] Oops, I forgot. We should free the FBitmap before exiting the program. ---------------------------------------------------------------------- engkin · 2021-04-20 16:04 Quote from: rabbit_dance on April 20, 2021, 03:54:22 pmthanks, but how to do so under console under such as linux? Here is an example. ---------------------------------------------------------------------- rabbit_dance · 2021-04-20 16:16 Quote from: engkin on April 20, 2021, 06:04:25 pmQuote from: rabbit_dance on April 20, 2021, 03:54:22 pmthanks, but how to do so under console under such as linux? Here is an example. the problem discussed in your post is not same to my problem. the code in the given example contains unit graphics, which does not contain in rtl and fcl. ---------------------------------------------------------------------- engkin · 2021-04-20 16:21 You know better what you need. The example gives you a canvas to draw on, that's all. ---------------------------------------------------------------------- engkin · 2021-04-20 16:29 I just saw your other thread and now I see what you mean.