How to install image library for freepascal on linux? lazarus / 21-General ---------------------------------------------------------------------- barracuda · 2023-08-01 11:36 Hello, First time I try freepascal, just installed it on linux Mint 20. I want to work with image library is there some library with fuctions that can direct read rows or cols from image? I did not find out libfcl-image in my repository and did not find out how to install it. Also I see I cannot post to Freepascal section why? ---------------------------------------------------------------------- Handoko · 2023-08-01 12:05 Hello barracuda, Welcome to the forum. Have you tried Lazarus? In short, Lazarus is Free Pascal plus something extra. If you want to build GUI programs or working with images, using Lazarus is easier. For example, in the link below has a demo showing how to load and read image data: https://forum.lazarus.freepascal.org/index.php/topic,37242.msg252828.h tml#msg252828 If you want to see more demos what can do using Lazarus: https://wiki.freepascal.org/Portal:HowTo_Demos ---------------------------------------------------------------------- Leledumbo · 2023-08-01 12:16 Quote from: barracuda on August 01, 2023, 01:36:00 pmFirst time I try freepascal, just installed it on linux Mint 20. I want to work with image library is there some library with fuctions that can direct read rows or cols from image? I did not find out libfcl-image in my repository and did not find out how to install it. In the tradition of Ubuntu packaging, I believe the units are scattered in whatever they name the packages. Try searching with the keyword "fcl", at least Ubuntu's package search web tells me there's fp-units-fcl. ---------------------------------------------------------------------- barracuda · 2023-08-01 12:33 Please, how to quote? I don't see quote button (lots of buttons here have no description they are white buttons and white text color). So I found the packages, but chatGPT recommended to look for libfcl- image2.6.4 and the packages you mention did not include description of the graphical library. Now I don't know if to install FP or Lazarus. Of sure I want something extra, but in this moment i want to do something really fast in terminal. I have tried a simple bash file using convert (ImageMagick) and I have found that the IM is not able to export pixel information for complete row or column. So I need to write this program to get better performence. The AI recommendation was this function: 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 function himage() {    values=() # Jednorozměrné pole pro ukládání hodnot    for x in {1..32}; do        value=$(convert w.png -format "%[pixel:p{$x,0}]" info:-)        value=${value//gray(/}        values+=("${value//)/}") # Přidání hodnoty do pole    done    echo "${values[@]}"} Which is very slow because this calls the convert 32 times. I think this would be really problem with higher resolution. Yet my question to Lazarus. Is it possible to use it to write program for terminal only, not the graphical interface? I would like to try graphical interface later. I was used to use Delphi 7, but having Windows XP, it's impossible to have run both the Delphi7 and linux with chatGPT  . I like to use AI in my first steps of programming, even it makes so many stupid mistakes. I learn this way ---------------------------------------------------------------------- Handoko · 2023-08-01 12:50 Quote from: barracuda on August 01, 2023, 02:33:03 pmYet my question to Lazarus. Is it possible to use it to write program for terminal only, not the graphical interface? Yes, you can use Lazarus to write Simple Program, Program and Console application. They all are console programs (terminal only). See img1 below, it is a screenshot captured when I did Lazarus main menu > File > New. Quote from: barracuda on August 01, 2023, 02:33:03 pmPlease, how to quote? You have 2 ways to do it. When replying someone post, there will be an "Insert Quote" button, see img2. Or you can use the Insert Quote Icon, see img3. ---------------------------------------------------------------------- Leledumbo · 2023-08-01 13:36 Quote from: barracuda on August 01, 2023, 02:33:03 pmSo I found the packages, but chatGPT recommended to look for libfcl-image2.6.4 Another reason to ditch that smart ass app. Forget whatever ChatGPT says, it knows too little. 2.6.4 is way to old and there's never a name libfcl-image, only fcl-image as a package. Quote from: barracuda on August 01, 2023, 02:33:03 pmand the packages you mention did not include description of the graphical library. Look at the filelist. It contains everything fcl-image. Quote from: barracuda on August 01, 2023, 02:33:03 pmI like to use AI in my first steps of programming, even it makes so many stupid mistakes. I learn this way  Don't. Be a real programmer by learning on your own. AI can help you later, not earlier, because you will need to feed it with a bunch of correct knowledge to fix its mistakes, which you don't have as a beginner. ---------------------------------------------------------------------- barracuda · 2023-08-01 13:47 I see fcl-unit fcl-unit-3.0.4 Both to install? ---------------------------------------------------------------------- wp · 2023-08-01 13:57 Quote from: barracuda on August 01, 2023, 03:47:25 pmI see fcl-unit fcl-unit-3.0.4 Both to install? ??? ChatGPT gives answers which are impressive at first sight, but I can say: When it comes to the ultimate test to run its proposed code through the compiler there is ALWAYS something which is wrong. Forget AI, go the classical way and begin reading: An introductory article for fcl-image is https://wiki.freepascal.org/fcl-image. It contains several code examples which you can copy and paste into a Lazarus editor window. This way you slowly can build up knowledge in this topic. Note the word "slowly"? Yes, everything needs its time. ---------------------------------------------------------------------- barracuda · 2023-08-01 14:07 Quote from: wp on August 01, 2023, 03:57:22 pmQuote from: barracuda on August 01, 2023, 03:47:25 pmForget AI, go the classical way and begin reading: An introductory article for fcl-image is https://wiki.freepascal.org/fcl-image. It contains several code examples which you can copy and paste into a Lazarus editor window. This way you slowly can build up knowledge in this topic. Note the word "slowly"? Yes, everything needs its time. I have experience many years of programming, learning PHP,JS,Jquery,C/C++,ahk,delphi. I always, always forget what I have learned during a year and a half. This would be waste of time. Getting older. My memory is not good to go this way. I can keep just small stuff which I really use for every day or once a month. My experience is to reach the goal not to learn without reaching the goal. ---------------------------------------------------------------------- barracuda · 2023-08-01 16:48 Quote from: Handoko on August 01, 2023, 02:50:52 pmQuote from: barracuda on August 01, 2023, 02:33:03 pmYet my question to Lazarus. Is it possible to use it to write program for terminal only, not the graphical interface? Yes, you can use Lazarus to write Simple Program, Program and Console application. They all are console programs (terminal only). See img1 below, it is a screenshot captured when I did Lazarus main menu > File > New. Quote from: barracuda on August 01, 2023, 02:33:03 pmPlease, how to quote? You have 2 ways to do it. When replying someone post, there will be an "Insert Quote" button, see img2. Or you can use the Insert Quote Icon, see img3. Thank you for the screenshot. I finally installed all three packages. The Lazarus took 1 GB of disk space. I see another project called FPCUnit for testing purposes. Is it better to use when I want to measure time of execution? ---------------------------------------------------------------------- Handoko · 2023-08-01 17:33 I usually use something like this to test the performance of my programs: 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, Dialogs, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure DoSomething;var  i, j: Integer;begin  for i := 1 to MaxInt div 1000 do  begin    j := i;    Application.ProcessMessages;  end;end; procedure TForm1.Button1Click(Sender: TObject);var  Start, Delta:   TDateTime;  Hr, Mn, Sc, Ms: Word; // hour, minute, second, millisecondbegin   Start := Now;   DoSomething;   Delta := Now - Start;  DecodeTime(Delta, Hr, Mn, Sc, Ms);  ShowMessage(    (Hr*60+Mn).ToString +':'+    Sc.ToString         +':'+    Ms.ToString    ); end; end. The source code is provided in the link below: ---------------------------------------------------------------------- barracuda · 2023-08-01 18:04 Thank you for your code. I am almost configurated but I have stucked one problem. There was Courier or Courier New font and I changed it to Tahoma but the spaces stayed extremly huge. For this reason I don't  see much of any code... Here is an example of code what I see: 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 begin  Img := TFPMemoryImage.Cr No more space left on my screen I mean the width. Usually I would see like 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 begin  Img := TFPMemoryImage.Create(32, 32);  try    // Načtení obrázku    try    ReadPNG(Img, 'w.png');    except      on E: Exception do      begin        Writeln('Chyba při načítání obrázku: ', E.Message); I mean the maximum width of the working area where the code is diplayed. The left strip with line numbers takes like 1/7,5 of my screen width. Is there something in the Lazarus what makes everything bigger? I don't mind the big size of text, but the spaces. It consumes like 200% of the character width. And that's crazy. ---------------------------------------------------------------------- wp · 2023-08-01 20:19 You cannot use Tahoma in the Lazarus editor because it assumes that every character has the same width - and Tahoma is a proportional font in which every character has its own width. It you don't like the "Courier" font select one with "Mono" in its name (Mono = mono-spaced = all characters have the same width). All the editor settings can be made when you right-click on the editor and select "Options". Select "Display" in the navigation tree to get to the font settings. I am using font size 9, and I don't use any extra character and line spacing. ---------------------------------------------------------------------- barracuda · 2023-08-02 02:07 I really cannot use Lazarus. Sorry. Do you have any other IDE for FreePascal which can use fonts like Tahoma or Arial Black? I think I can use FreePascal for designing but not for programming. Regarding use of text and fonts settings even xed is much better and user friendly. I see no reason for missing this type of fonts. ---------------------------------------------------------------------- Handoko · 2023-08-02 04:21 Interesting. I never know Xed Editor can use Tahoma or Arial Black fonts. ---------------------------------------------------------------------- barracuda · 2023-08-02 09:51 Quote from: Handoko on August 02, 2023, 06:21:13 amInteresting. I never know Xed Editor can use Tahoma or Arial Black fonts. I can check what font I use (when I will be on Linux). I've spended time installing new fans and they go on full throttle 1800 kind of noizy and frustrating. I need to find some software for Win XP to get it under control since I run linux on VM. ---------------------------------------------------------------------- barracuda · 2023-08-02 17:02 Quote from: Handoko on August 02, 2023, 06:21:13 amInteresting. I never know Xed Editor can use Tahoma or Arial Black fonts. So in xed I am using scheme Oblivion. It seems that the font is Monospace regular. So I set Monospace Regular, same size and it is not identical in Lazarus. Lazarus uses very big spaces. For example this: "ReadPNG(Img, 'w.png');" looks like this "R e a d P N G (  I  mg , ' w. p n g '  )  ;" This is very unpleasant for me very inconvenient. But in the same time I'm having another inconvenient problem when I hear the noise from new fan(s). An I cannot find how to get down the RPMs. It seems like no support in OS, while on Win XP Speedfan detects it, it does not slow it down. And lm-sensort on Linux mint, did not detect. ---------------------------------------------------------------------- Handoko · 2023-08-03 05:15 Quote from: barracuda on August 02, 2023, 07:02:38 pmLazarus uses very big spaces. Please provide a screenshot. Lazarus has been used by a lot of users for years, I never heard the font issue as you described. The img1 below is the screenshot of my Lazarus Source Editor, using its default font DejaVu Sans Mono and its default settings. If yours looks much different from the img1, maybe you have accidentally changed the settings, see img2. Or maybe there were some problems with your installation. Quote from: barracuda on August 02, 2023, 07:02:38 pmAn I cannot find how to get down the RPMs. Did you mean the Linux rpm packages? If yes, here is the link: https://sourceforge.net/projects/lazarus/files/ Quote from: barracuda on August 02, 2023, 07:02:38 pmIt seems like no support in OS, while on Win XP Speedfan detects it, it does not slow it down. And lm-sensort on Linux mint, did not detect. I cannot fully understand what you meant. Please provide more information. ---------------------------------------------------------------------- Thaddy · 2023-08-03 07:13 As long as you install those fonts correctly, it does.... And cross- platform. The issue at hand is simply that the font - or the font family - is not there. ---------------------------------------------------------------------- barracuda · 2023-08-03 11:04 Quote from: Handoko on August 03, 2023, 07:15:22 amQuote from: barracuda on August 02, 2023, 07:02:38 pmAn I cannot find how to get down the RPMs. I fixed the issue with fans. I found BIOS option Monitor->Q-Fan profile->Quite Not it is very quite. "RPM" I mean the unit for fan speed rotations per minute. Ok, I gonna start the VM to send screenshot. ---------------------------------------------------------------------- barracuda · 2023-08-03 11:54 I have tried to install CodeTyphon with GTK2 and it was unsuccessful. After I removed it, Lazarus cannot find fpc. I don't know how to fix it. Sending the screenshots. ---------------------------------------------------------------------- Handoko · 2023-08-03 12:36 I can see your issue now. Unfortunately I don't know what causes it. My guesses, maybe the font files were damaged or maybe you need to reinstall your Lazarus. I saw you're using older version of Lazarus installed using your OS software manager. Don't use that. You should use the latest version provided by official Lazarus team, here: https://sourceforge.net/projects/lazarus/files/ I think before you reinstall the Lazarus, you may need to do a complete Lazarus/FPC removal: https://forum.lazarus.freepascal.org/index.php/topic,38828.msg265293.h tml#msg265293 I don't know why you want to use CodeTyphon. I and many users here do not use CodeTyphon, you should ask your CodeTyphon issue on their forum. ---------------------------------------------------------------------- barracuda · 2023-08-03 22:12 I can try reinstall, but I doubt it will run. Win XP - VM machine->Mint 20-> updates stopped... The updates bring worsening of RAM consumption. I'm not completely ready to go on non-VM mint installation. I'm sure with 8GB RAM there would be no problems, but I think I could find another problem like I still need some Windows XP applications, possible drivers issues, etc. I'm using VM for I am learning the basics on linux that I need before I go to fresh non-VM installation. ---------------------------------------------------------------------- wp · 2023-08-03 22:51 I get a similar screenshot as your laz01.png when I set the editor font to a proportional font - see my screen shot (here: Deja Vu Sans Light). As I already said: don't do this. Select a mono-spaced font, such as Deja Vu Sans Mono (see the other screenshot) and it will work. ---------------------------------------------------------------------- barracuda · 2023-08-03 23:32 Quote from: wp on August 04, 2023, 12:51:09 amI get a similar screenshot as your laz01.png when I set the editor font to a proportional font - see my screen shot (here: Deja Vu Sans Light). As I already said: don't do this. Select a mono-spaced font, such as Deja Vu Sans Mono (see the other screenshot) and it will work. I dont see the settings, just uninstalled lazarus. I cannot install it according the guide as posted above. ---------------------------------------------------------------------- barracuda · 2023-08-04 08:11 I reinstalled Lazarus and never will follow any guide like that one complicated in future (as described in the link). The only safe solution for me as newbie is the Lazarus from repo installation. I have put there Libration Open as far as I remember it correctly, but I would prefer to find a bolder one. The current mono fonts are somewhat thin for me so I need to enlarge the size to 20 instead stayin' with 16. ---------------------------------------------------------------------- Dzandaa · 2023-08-04 09:07 Hi, I use Linux Mint for many years and Pascal Lazarus for about one year. I've just installed it for a friend on a old laptop 2 cores a few days ago. I'm on Linux Mint 20.2 Cinnamon 64Bits, Kernel 5.15.0-78-generic newer versions have sometimes problems with old computers and NVidia Graphics cards. Don't use the Lazarus version on Mint repository, it is not the latest. Uninstall it  with the "Software manager" or Uninstall it completely with "Synaptic Package Manager" Search for "fpc", look what is installed (Green square), select  it with Right Click and  "Mark for Removal" then "Apply" Do the same with "lazarus" For the installation, I download the 3 packages from here: https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64 %20DEB/Lazarus%202.2.6/ I install the 3 packages in order: fpc-laz_3.2.2-210709_amd64.deb fpc-src_3.2.2-210709_amd64.deb lazarus-project_2.2.6-0_amd64.deb By clicking on the .deb file you run the "Archive Manager" then "Install" After the first run, I install "anchordockingdsgn" from "Package->Install/Uninstall Packages" to have a pleasant environment. For Graphic, I use "BGRABitmap" and "BGRAControls" from "Package->Online Package Manager" Hope that help. B-> ---------------------------------------------------------------------- barracuda · 2023-08-09 21:19 Quote from: Dzandaa on August 04, 2023, 11:07:16 amHi, I use Linux Mint for many years and Pascal Lazarus for about one year. I've just installed it for a friend on a old laptop 2 cores a few days ago. I'm on Linux Mint 20.2 Cinnamon 64Bits, Kernel 5.15.0-78-generic newer versions have sometimes problems with old computers and NVidia Graphics cards. Don't use the Lazarus version on Mint repository, it is not the latest. Uninstall it  with the "Software manager" or Uninstall it completely with "Synaptic Package Manager" Search for "fpc", look what is installed (Green square), select  it with Right Click and  "Mark for Removal" then "Apply" Do the same with "lazarus" For the installation, I download the 3 packages from here: https://sourceforge.net/projects/lazarus/files/Lazarus%20Linux%20amd64 %20DEB/Lazarus%202.2.6/ I install the 3 packages in order: fpc-laz_3.2.2-210709_amd64.deb fpc-src_3.2.2-210709_amd64.deb lazarus-project_2.2.6-0_amd64.deb By clicking on the .deb file you run the "Archive Manager" then "Install" After the first run, I install "anchordockingdsgn" from "Package->Install/Uninstall Packages" to have a pleasant environment. For Graphic, I use "BGRABitmap" and "BGRAControls" from "Package->Online Package Manager" Hope that help. B-> Thank you for your description and links. lazarus, fpc, fpc src and fp (fp unit) was needed to uninstall all the things. Now I'm not sure if to uninstall the libfprint, probably something different, so not. Now installing sudo gdebi -n -q  fpc-laz_3.2.2-210709_amd64.deb fpc- src_3.2.2-210709_amd64.deb lazarus-project_2.2.6-0_amd64.deb It seems that it is installed but I cannot run it: sudo gdebi -n -q fpc-laz_3.2.2-210709_amd64.deb fpc- src_3.2.2-210709_amd64.deb lazarus-project_2.2.6-0_amd64.deb (Database is loading... currently 436,567 files and directories are installed.) Preparing to replace fpc-laz_3.2.2-210709_amd64.deb... Unpacking fpc-laz (3.2.2)... Setting up package fpc-laz (3.2.2)... Running on Linux Write permission in /etc. Writing a sample configuration file to /etc/fpc.cfg Writing a sample configuration file to /usr/lib/fpc/3.2.2/ide/text/fp.cfg Writing a sample configuration file to /usr/lib/fpc/3.2.2/ide/text/fp.ini Writing a sample configuration file to /etc/fppkg.cfg Writing a sample configuration file to /etc/fppkg/default Processing triggers for package man-db (2.9.1-1)... $ lazarus bash: lazarus: command not found $ fpc-laz bash: fpc-laz: command not found fpc is installed. I cannot find the lazarus in xFce menu (mint 20) ---------------------------------------------------------------------- Dzandaa · 2023-08-10 08:26 Hi Barracuda I don't use Mint xFce, but Cinnamon. If your computer is not to old and 64bits, I recommend Cinnamon. Lazarus is the menu "Programming->Lazarus". Lazarus is installed in /usr/bin The Command is "startlazarus" or "startlazarus yourproject" B-> ---------------------------------------------------------------------- barracuda · 2023-08-10 08:56 The lazarus project cannot be installed. Thank you. RAD tool for Free Pascal Lazarus is a free and open-source IDE and RAD tool for Free Pascal, utilizing the Lazarus Component Library (LCL). The LCL is also included in this package. Visit http://www.lazarus.freepascal.org Do you wish to install the package? [Y/n]: Y Selecting the previously unselected package lazarus-project. dpkg: considering lazarus-project_2.2.6-0_amd64.deb containing package lazarus-project: lazarus-project is in conflict with lazarus-src lazarus-src-2.0 provides lazarus-src and is present and installed. dpkg: error processing archive lazarus-project_2.2.6-0_amd64.deb (--install): package conflict - will not install lazarus-project Errors were encountered while processing: lazarus-project_2.2.6-0_amd64.deb ---------------------------------------------------------------------- barracuda · 2023-08-10 09:54 Finally! So I wanted to uninstall all and then I have found that there is fp- src 2.0 or something like that still installed. So I uninstalled it and then I could run the newer version install from .deb file. But it told me that this version is already installed so I aborted the install and then I could not to install lazarus newer version. I tried gdebi, apt purge, apt remove, apt reinstall, apt  --fix-broken etc. etc. Then chatGPT helped. It suggested first that I should update the packages. I said no!!! And then I copied the my tries from terminal and the commands and errors and he suggested dpkg -i which ignore dependencies. I think that the was nothing broken or missing I just needed to install the newer version but the system with apt it had seen the lower version like fp-src-2.0 or something like that. I'd like to try your links or project you suggested on the beginning of the thread. I need to create my own viewer for images very simple and easy, I will explain. May you help me? I need an image of size like 1200x1200 to resize to fit my screen which is 800x600 and to display edit box with the file name. The trick I need to do is that I need to open files from terminal like in an array img1 img2 img3 etc. ---------------------------------------------------------------------- barracuda · 2023-08-10 18:33 Solved. I updated the config but selection Update button. I can run the Lazarus, but maybe it starts with old config. It seems that I should do apt purge after I uninstalled old version. This is the message I got when I start Lazarus [Invalid Configuration Directory Found] Welcome to Lazarus. The discovered IDE Configuration has previously been used by a different Lazarus installation. If you have two or more separate Lazarus installations, these installations should not share the same configuration. This could lead to conflicts and make your Lazarus installations unstable. If you have only one installation and have copied/moved the Lazarus executable file, you can update this configuration. If you intend to use two different versions of Lazarus, you must launch the second version with the command-line parameter primary- config-path or pcp. For example: /usr/share/lazarus/2.2.6/startlazarus --pcp=~/.lazarus_test Choose: %:s* Update Information: Use this configuration and update it for future use with Lazarus. The old installation will no longer use it.     Ignore: Use this configuration but keep the warning. This could lead to conflicts with other installations.     Cancel: Exit right now. You can resolve the issue by launching Lazarus with the correct configuration afterward. Additional Information: This configuration is for: /home/user/.lazarus Belongs to the Lazarus installation in /usr/lib/lazarus/2.0.6/lazarus- gtk2 The current IDE was launched from: /usr/share/lazarus/2.2.6/lazarus ---------------------------------------------------------------------- barracuda · 2023-08-10 19:18 Can you help me how to control the Lazarus? I just cannot grasp it. I tried to compile project downloaded from forum. I see two lines highlited one is green background and one is violet background. But I could not do anything because the menu of Lazarus was suspended. So I had to kill lazarus because I could not control it. Only thing I could do is to move the windows or switch between them. But I also could not found what hotkeys to be used to hide Messages window, which when I want to read the messages takes 2/3 of my screen so I see like 2 lines of the code. Hence I need to close the Messages Window or do display it instead of having both windows (Source Code and the Messages) open. Also what is hotkey to run the app after compilation. Thank you. PS: I tried to compile this https://forum.lazarus.freepascal.org/index .php/topic,37242.msg252828.html#msg252828 from hondako. ---------------------------------------------------------------------- Handoko · 2023-08-11 02:26 I remember you said your screen resolution was 800x600. That is too low, you will have difficult time working in Lazarus using low resolution setting. Can you increase the resolution? Quote from: barracuda on August 10, 2023, 09:18:22 pm... But I could not do anything because the menu of Lazarus was suspended. So I had to kill lazarus because I could not control it. I am not sure what happened. Can you provide a screenshot? Quote from: barracuda on August 10, 2023, 09:18:22 pmAlso what is hotkey to run the app after compilation. Thank you. These are the common used hotkeys: F9            = run Ctrl+Shift+F9 = run without debugging F2            = stop Ctrl+F9       = compile Shift+F9      = build F12           = toogle unit/form view F11           = object inspector ---------------------------------------------------------------------- barracuda · 2023-08-11 22:51 Changing resolution on VM is complicated. The screen resolution of my display is not supported on VM. I can work with it. It is a slower solution needing a patience. I need to switch manually between windows and that is a bit pissing. ---------------------------------------------------------------------- Handoko · 2023-08-12 09:25 Quote from: barracuda on August 10, 2023, 11:54:15 amI need to create my own viewer for images very simple and easy, I will explain. May you help me? I need an image of size like 1200x1200 to resize to fit my screen which is 800x600 and to display edit box with the file name. The trick I need to do is that I need to open files from terminal like in an array img1 img2 img3 etc. I quickly wrote a demo. I haven't tested it thoroughly, it may contain bugs. 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, LCLType,  ExtDlgs, ExtCtrls; type   TInfo = record    Name:  string;    Image: TImage;  end;   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Image1:  TImage;    Label1:  TLabel;    OpenPictureDialog1: TOpenPictureDialog;    procedure Button1Click(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);  procedure FormCreate(Sender: TObject);    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure FormResize(Sender: TObject);  private    Index:     Integer;        // Index of the image currently showing    Data:      array of TInfo; // Loaded image data and their names    isViewing: Boolean;    procedure CenterFilename;    procedure ShowLoadedImage;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.CenterFilename;begin  Label1.AutoSize  := False;  Label1.Alignment := taCenter;  Label1.Left      := 0;  Label1.Width   := Form1.Width;end; procedure TForm1.ShowLoadedImage;var  Count: Integer;begin  Count := Length(Data);  if Count <= 0 then Exit;  if Index > Count-1 then Exit;  Image1.Picture.Assign(Data[Index].Image.Picture);  Label1.Caption := Data[Index].Name;  CenterFilename;end; procedure TForm1.Button1Click(Sender: TObject);begin  if not(OpenPictureDialog1.Execute) then Exit;  try    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);    Button1.Visible     := False;    Label1.Caption      := ExtractFileName(OpenPictureDialog1.FileName);    isViewing           := True;    CenterFilename;  except    ShowMessage('Cannot open the file.');  end;end; procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  case Key of    VK_ESCAPE: // Exit program      Close;    VK_F5:     // Background color      case Color of        clDefault: Color := clBlack;        clBlack:   Color := clGray;        clGray:    Color := clWhite;        clWhite:   Color := clDefault;        else       Color := clDefault;      end;    VK_F6:     // Info color;      case Label1.Font.Color of        clDefault: Label1.Font.Color := clBlack;        clBlack:   Label1.Font.Color := clGray;        clGray:    Label1.Font.Color := clWhite;        clWhite:   Label1.Font.Color := clYellow;        clYellow:  Label1.Font.Color := clRed;        clRed:     Label1.Font.Color := clBlue;        clBlue:    Label1.Font.Color := clDefault;        else       Label1.Font.Color := clDefault;        end;    VK_F7:     // Proportinal stretch      Image1.Proportional := not(Image1.Proportional);    VK_F8:     // Fullscreen modes      case WindowState of        wsNormal:     WindowState := wsMaximized;      wsMaximized:  WindowState := wsFullScreen;        wsFullScreen: WindowState := wsNormal;      end;    VK_LEFT:   // Show preview image      begin        Dec(Index);        if Index < 0 then          Index := Length(Data)-1;        ShowLoadedImage;      end;    VK_RIGHT,    VK_SPACE:  // Show next image      begin        Inc(Index);        if Index >= Length(Data) then          Index := 0;        Image1.Proportional := True;        Image1.Stretch      := True;        Image1.Align        := alClient;        Button1.Visible   := False;        ShowLoadedImage;      end;  end;end; procedure TForm1.FormResize(Sender: TObject);begin  if isViewing then    CenterFilename;end; procedure TForm1.FormCreate(Sender: TObject);var  Tmp:   TImage;  Count: Integer;  i:     Integer;begin   Constraints.MinHeight := 240;  Constraints.MinWidth  := 320;  KeyPreview            := True;  Caption               := 'Image Viewer';  Button1.Caption       := 'Open';  Image1.Proportional   := True;  Image1.Stretch        := True;  Image1.Align          := alClient;  Index                 := 0;  isViewing             := False;   // Try to load images using names supplied by parameter string  for i := 1 to ParamCount do  begin    Tmp := TImage.Create(nil);    try      Tmp.Picture.LoadFromFile(ParamStr(i));      Count := Length(Data);    Inc(Count);      SetLength(Data, Count);      Data[Count-1].Image := TImage.Create(nil);      Data[Count-1].Image.Picture.Assign(Tmp.Picture);      Data[Count-1].Name := ParamStr(i);    finally      Tmp.Free;    end;  end;   if Length(Data) > 0 then // Managed to load some images  begin    isViewing := True;    ShowLoadedImage;  end; end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);var  i: Integer;begin  if Length(Data) <= 0 then Exit;  for i := 0 to Length(Data)-1 do    Data[i].Image.Free;  SetLength(Data, 0);end; end. It supports command line parameter, so you can run from terminal passing the file names. There are 3 images in the attachment for testing. So you can run it by doing this in the termninal: ./project1 img1.jpg img2.jpg img3.jpg It uses TImage for beginner friendly reason, see line #15. For serious usage, you should use other more lightweight alternative which also has better file format support for example FPImage, but the code will be a bit more trickly if you're not familiar with graphics programming. ---------------------------------------------------------------------- barracuda · 2023-08-12 17:11 Hello friend, thank you much for your afford. Will you have a patience with me? Before you have created the project I have started to learn with one demo from you and I would like to ask you new question about that project, which I have modified to resize image. So I will create new demo, I will pack the directory and upload it. ---------------------------------------------------------------------- barracuda · 2023-08-14 20:16 Quote from: Handoko on August 12, 2023, 11:25:57 amIt uses TImage for beginner friendly reason, see line #15. For serious usage, you should use other more lightweight alternative which also has better file format support for example FPImage, but the code will be a bit more trickly if you're not familiar with graphics programming. Once again thank you. I think that the code tries to load all the images? So if I have RGB 1024x1024 it will consume a lot of memory. I am running low RAM because of Firefox and Lazarus. 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 procedure TForm1.FormCreate(Sender: TObject);var  Tmp:   TImage;  Count: Integer;  i:     Integer;begin   Constraints.MinHeight := 600;  Constraints.MinWidth  := 800;  KeyPreview            := True;  Caption               := 'Image Viewer';  Button1.Caption       := 'Open';  Image1.Proportional   := True;  Image1.Stretch        := True;  Image1.Align          := alClient;  Index                 := 0;  isViewing             := False;   // Try to load images using names supplied by parameter string  for i := 1 to ParamCount do  begin    Tmp := TImage.Create(nil);    try      Tmp.Picture.LoadFromFile(ParamStr(i));      Count := Length(Data);    Inc(Count);      SetLength(Data, Count);      Data[Count-1].Image := TImage.Create(nil);      Data[Count-1].Image.Picture.Assign(Tmp.Picture);      Data[Count-1].Name := ParamStr(i);    finally      Tmp.Free;    end;  end;   if Length(Data) > 0 then // Managed to load some images  begin    isViewing := True;    ShowLoadedImage;  end;end;  My idea was to load the list of files, not the list of images. But I can experiment with it to change it. ---------------------------------------------------------------------- marcov · 2023-08-14 21:07 QuoteRGB 1280x1024 3.75 MB. That means 270 images or so per GB of memory. How many do you have on that command line !?!? ---------------------------------------------------------------------- barracuda · 2023-08-14 22:45 Quote from: marcov on August 14, 2023, 11:07:34 pmQuoteRGB 1280x1024 3.75 MB. That means 270 images or so per GB of memory. How many do you have on that command line !?!? It depends on how many I will download. Probably up to 50 images. I have very small amount of memory. It can be like 250 MB when it is alarming. 150 is almost critical. ---------------------------------------------------------------------- barracuda · 2023-08-14 22:49 Quote from: Handoko on August 12, 2023, 11:25:57 amI quickly wrote a demo. I haven't tested it thoroughly, it may contain bugs. Why the image when I open it exactly fits the height? I see .Width is 800 which is nonsense because the height is 600 and the image is square. I need to center the image but 800-800 = 0 so I see it on left side. See CenterFilename ... 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, LCLType,  ExtDlgs, ExtCtrls; type   TInfo = record    Name:  string;    Image: TImage;  end;   { TForm1 }   TForm1 = class(TForm)    ComboBox1: TComboBox;    Label1: TLabel;    Button1: TButton;    EditFileName: TEdit;    Image1:  TImage;    OpenPictureDialog1: TOpenPictureDialog;    procedure Button1Click(Sender: TObject);    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure FormResize(Sender: TObject);  private    Index:     Integer;        // Index of the image currently showing    Data:      array of TInfo; // Loaded image data and their names    isViewing: Boolean;    procedure CenterFilename;    procedure ShowLoadedImage;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.CenterFilename;begin  EditFileName.AutoSize := False;  EditFileName.Width := ClientWidth - round(ClientWidth div 30);  EditFileName.Top := Screen.Height-round(Screen.Height div 10);  EditFileName.Left := -10+round((ClientWidth div 2) - (EditFileName.Width div 2) ); // Vycentrování horizontálně  Image1.Left := round((Width - Image1.Width) div 2);end; procedure TForm1.ShowLoadedImage;var  Count: Integer;begin  Label1.Visible := False;  Button1.Visible := False;  Label1.Visible := False;  Count := Length(Data);  if Count <= 0 then Exit;  if Index > Count-1 then Exit;  Image1.Picture.Assign(Data[Index].Image.Picture);  EditFileName.Text := Data[Index].Name;  CenterFilename;end; procedure TForm1.Button1Click(Sender: TObject);begin  if not(OpenPictureDialog1.Execute) then Exit;  try    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);    Button1.Visible     := False;    EditFileName.Text   := ExtractFileName(OpenPictureDialog1.FileName);    isViewing           := True;    CenterFilename;  except    ShowMessage('Cannot open the file.');  end;end; procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  case Key of    VK_ESCAPE: // Exit program      Close;    VK_F5:     // Background color      case Color of        clDefault: Color := clBlack;        clBlack:   Color := clGray;        clGray:    Color := clWhite;        clWhite:   Color := clDefault;        else       Color := clDefault;      end;    VK_F6:     // Info color;      case EditFileName.Font.Color of        clDefault: EditFileName.Font.Color := clBlack;        clBlack:   EditFileName.Font.Color := clGray;        clGray:    EditFileName.Font.Color := clWhite;        clWhite:   EditFileName.Font.Color := clYellow;        clYellow:  EditFileName.Font.Color := clRed;        clRed:     EditFileName.Font.Color := clBlue;        clBlue:    EditFileName.Font.Color := clDefault;        else       EditFileName.Font.Color := clDefault;        end;    VK_F7:     // Proportinal stretch      Image1.Proportional := not(Image1.Proportional);    VK_F8:     // Fullscreen modes      case WindowState of        wsNormal:     WindowState := wsMaximized;      wsMaximized:  WindowState := wsFullScreen;        wsFullScreen: WindowState := wsNormal;      end;    VK_LEFT:   // Show preview image      begin        Dec(Index);        if Index < 0 then          Index := Length(Data)-1;        ShowLoadedImage;      end;    VK_RIGHT,    VK_SPACE:  // Show next image      begin        Inc(Index);        if Index >= Length(Data) then          Index := 0;        Image1.Proportional := True;        Image1.Stretch      := True;        Image1.Align        := alClient;        Button1.Visible   := False;        ShowLoadedImage;      end;  end;end; procedure TForm1.FormResize(Sender: TObject);begin  if isViewing then    CenterFilename;end; procedure TForm1.FormCreate(Sender: TObject);var  Tmp:   TImage;  Count: Integer;  i:     Integer;begin   Constraints.MinHeight := 600;  Constraints.MinWidth  := 800;  KeyPreview            := True;  Caption               := 'Image Viewer';  Button1.Caption       := 'Open';  Image1.Proportional   := True;  Image1.Stretch        := True;  Image1.Align          := alClient;  Index                 := 0;  isViewing             := False;   // Try to load images using names supplied by parameter string  for i := 1 to ParamCount do  begin    Tmp := TImage.Create(nil);    try      Tmp.Picture.LoadFromFile(ParamStr(i));      Count := Length(Data);    Inc(Count);      SetLength(Data, Count);      Data[Count-1].Image := TImage.Create(nil);      Data[Count-1].Image.Picture.Assign(Tmp.Picture);      Data[Count-1].Name := ParamStr(i);    finally      Tmp.Free;    end;  end;   if Length(Data) > 0 then // Managed to load some images  begin    isViewing := True;    ShowLoadedImage;  end; end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);var  i: Integer;begin  if Length(Data) <= 0 then Exit;  for i := 0 to Length(Data)-1 do    Data[i].Image.Free;  SetLength(Data, 0);end; end. ---------------------------------------------------------------------- jamie · 2023-08-15 00:48 I take it you are trying to maintain the aspect ratio of the image regardless of viewing size ? ---------------------------------------------------------------------- barracuda · 2023-08-15 09:13 Quote from: jamie on August 15, 2023, 02:48:13 amI take it you are trying to maintain the aspect ratio of the image regardless of viewing size ? In monday night, I tried to modify few thing in the demo. My goals: 1) To keep aspect ratio of the image. 2) Calculate the ratio needed to resize the image to height of the screen. 2.1) Maybe this goal will be changed to different calculation, later. 3) To calculate and to center the edit box (horizontally). The position is at bottom. 4) To center the image (horizontally). Both goals to be done in the same function. I failed At point 2. I found that the image width value 800 is wrong. What I would expect. If I'm having height 600, then the image should be 600x600 with the original ratio (proportional change). The I can calculate the correct left position. I calculate the spacing: 800-600 = 200. I devied the spacing by 2. So I need to have a space 100 on left and 100 on right. So left=100. So the question is why there is TImage.width=800 instead TImage.width=600? I would like to continue solving next steps with the edit control. For example. How to make it semitransparent? I think this will be harder. I quess if I want semitransparent background, I will need to calculate the bounds of the control, and then I will need to calculate overwrap in the image. I could copy the area in image to new image, modify colors in the new image, and then use it as a background for the edit box. Right? Then I will need to create onChange even for the edit box and when I will press enter, this will change the file name to value in the box. Or I could better run a bash script to change it to make more easier to control the filename. I could use the viewer just for viewing images and the enter would send a command to script. Something like: img_rename_rules.sh "downloaded_image.jpg" ---------------------------------------------------------------------- Handoko · 2023-08-15 10:16 Quote from: barracuda on August 15, 2023, 11:13:49 amSo the question is why there is TImage.width=800 instead TImage.width=600? Because of this: 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   Image1.Align          := alClient; Quote from: barracuda on August 15, 2023, 11:13:49 amI would like to continue solving next steps with the edit control. For example. How to make it semitransparent? I think this will be harder. Impossible, unless you're clever enough to hack into how the TEdit works. That's why I used TLabel. ---------------------------------------------------------------------- barracuda · 2023-08-15 14:43 Quote from: Handoko on August 15, 2023, 12:16:20 pmImpossible, unless you're clever enough to hack into how the TEdit works. That's why I used TLabel. So if I understand you correctly. I cannot even set the background image to it? Here I read about the semitransparency https://stackoverflow.com/questions/3714495/how-to-make-a-tmemo-and- tedit-with-a-transparent-background JVCL can do that using TJvMemo ---------------------------------------------------------------------- Handoko · 2023-08-15 15:28 Saying that is impossible, actually is wrong. Programmer + Time + Persistent can make impossible things become possible. Winning a chess game against a world chess champion is almost impossible. But programmers managed to write program to play chess and defeated Garry Kasparov in 1977. So the question is, how much effort are you willing to spend to make TEdit to support semi transparent background? Why not just use a TLabel? TLabel does not support background, if you really need a (semi transparent) background, you can use a TPaintBox or you can paint directly on the TImage.Canvas. If you haven't known, you can use TImage.Canvas.TextOut to write text, which is the easiest solution I think. ---------------------------------------------------------------------- lainz · 2023-08-15 15:42 There is Custom Drawn edit control, that you can  paint as you wish... ---------------------------------------------------------------------- barracuda · 2023-08-15 22:19 Quote from: lainz on August 15, 2023, 05:42:10 pmThere is Custom Drawn edit control, that you can  paint as you wish... It's not clear to me how to get TCDEdit into the Unit 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 interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLType,  ExtDlgs, ExtCtrls,  customdrawndrawers,  customdrawncontrols;...   TForm1 = class(TForm)    ComboBox1: TComboBox;    Label1: TLabel;    Button1: TButton;    EditFileName: TCDEdit;  Or how to bind the event procedures here: 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 EditFileName.OnClick := @MyEditClick;EditFileName.OnKeyDown := @MyEditKeyDown; Errors for example: unit1.pas(174,27) Error: Incompatible types: got "" expected "" I just cannot make it working. Any idea how to compile it? When I press F11 I see this error: Cannot find component of class "TCDEdit". It is not registered with RegisterClass and no lfm file was found. A unit is required: /home/user/FreePascal/ImageViewer2/unit1.pas ---------------------------------------------------------------------- jamie · 2023-08-15 23:13 https://www.youtube.com/watch?v=kJtVMZqON7U Yawn ---------------------------------------------------------------------- Handoko · 2023-08-16 02:43 No need to use any third party component. Try the code below. It shows how to stretch-drawing image, semi transparent rectangle and write text using only TCanvas. 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, ExtCtrls, StdCtrls, LCLType; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Image1: TImage;    procedure Button1Click(Sender: TObject);  private    procedure LoadImage;    procedure DrawCenterRectangle;    procedure WriteCenterText;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.LoadImage;const  ImageFile = 'img.png';var  Tmp: TPicture;begin  Image1.SetBounds(0, 0, Width, Height);  Image1.Picture.Clear;  Tmp := TPicture.Create;  try    Tmp.LoadFromFile(ImageFile);    Image1.Canvas.StretchDraw(ClientRect, Tmp.Bitmap);  finally    Tmp.Free;  end;end; procedure ChangeColor(var Data: Byte);const  Shift = 64; // 25% whitevar  Temp: Integer;begin  Temp := Data + Shift;  if (Temp > 255) then Temp := 255    else      if (Temp < 0) then Temp := 0;  Data := Temp;end; procedure TForm1.DrawCenterRectangle;const  BoxWidth  = 100;  BoxHeight = 20;var  ScanData:       PRGBQuad;  Xstart, Ystart: Integer;  Xend, Yend:     Integer;  X, Y:           Integer;begin   // Calculate Box position  Xstart := (Width - BoxWidth)   div 2;  Ystart := (Height - BoxHeight) div 2;  Xend   := Xstart + BoxWidth;  Yend   := Ystart + BoxHeight;   // Draw semi transparent rectangle  Image1.Picture.Bitmap.BeginUpdate;  for Y := Ystart to (Yend-1) do  begin    ScanData := Image1.Picture.Bitmap.ScanLine[Y];    for X:= 0 to (Image1.Picture.Bitmap.Width-1) do    begin      if (X >= Xstart) then      begin        ChangeColor(ScanData^.rgbRed);        ChangeColor(ScanData^.rgbGreen);        ChangeColor(ScanData^.rgbBlue);      end;      Inc(ScanData);      if X >= Xend then Break;    end;  end;  Image1.Picture.Bitmap.EndUpdate; end; procedure TForm1.WriteCenterText;const  Something = 'Hello';var  X, Y, W, H: Integer;begin  H := Image1.Canvas.TextHeight(Something);  W := Image1.Canvas.TextWidth(Something);  X := (Width - W)  div 2;  Y := (Height - H) div 2;  Image1.Canvas.Brush.Style := bsClear;  Image1.Canvas.Font.Color  := clWhite;  Image1.Canvas.TextOut(X, Y, Something);end; procedure TForm1.Button1Click(Sender: TObject);begin  LoadImage;  DrawCenterRectangle;  WriteCenterText;end; end. I quickly wrote and tested the code on Linux only, it may contain bugs. Room for improvements: - Instead of using Image1, draw directly on Form.Canvas - Fullscreen and proportional image loading not implemented ---------------------------------------------------------------------- barracuda · 2023-08-16 11:20 See, my system is way too slow. Will I solve one question whole week? It takes like hour to start mint and firefox and lazarus. If any shit happens like stupid VM Player starts to open FF Browser on Win XP while working on mint, everything can crash. I can wait till the night to test one program. Can you just answer a simple question? I will learn nothing otherwise. Why when I tried to install a package called CustomDrawn on Lazarus, I cannot add any component to Form. I don't see the components called TCDButton, TCDEdit etc. Is it like, they don't really exist? So it is not enough to use the "use" unit, but it is needed to install the package. I thought it should print some error like unit not defined or something in the way. But I am asking now why I don't see the components when I would like to add them to form. Also the previous question was... what was wrong with my code. I am just trying to understand how the things work. If just swapping to completely new code/program, I can learn nothing. It took me like one day to half understand the code, but still not working as I expected. So you can produce like one program one day but my PC and I we are way too slow to grasp it. ---------------------------------------------------------------------- KodeZwerg · 2023-08-16 11:54 What is the benefit to run a virtual machine on a physical machine that is not good enough to run the virtual machine smooth? Why you make your work more complicated than it needed to be? Just install Lazarus with its cross compilers on your base machine and be happy using it without any lags or installation problems etc... ? ---------------------------------------------------------------------- TRon · 2023-08-16 12:11 In addition to KodeZwerg you could also opt for dual-booting. But honestly I do not quite get it as I used to run VBox on windows XP on a core2duo (e5800) from ages ago and that ran just fine (though not the fastest in any way). It just has to do with your configuration (memory, bios settings) and not expecting to run something like KDE (openbox, xfce or qt are better suited for slow configurations). Puppies are great for the Linux job. ---------------------------------------------------------------------- Handoko · 2023-08-16 12:22 To be able to run a virtual machine smoothly, one needs to have good multicore processor with plenty of RAM. The prices of computer memory have been dropped significantly. A 8 GB DDR3 used RAM costs less than US$ 10 in where I live. Maybe OP needs to add more RAM. Quote from: barracuda on August 16, 2023, 01:20:31 pmWhy when I tried to install a package called CustomDrawn on Lazarus, I cannot add any component to Form. I don't see the components called TCDButton, TCDEdit etc. I do not use CustomDrawn, but last time I tried it, it was buggy and unmaintained. I just tried to install the package and it really appeared on the component tab. See the attached screenshot.  If you're having problem finding a component, you can use this shortcut: Ctrl + Alt + P = find a component If the component cannot be found, you probably haven't installed it correctly. You can install CustomDrawn package by doing this: Lazarus main menu > Package > Install/Uninstall Packages > in the right panel panel, select: customdrawn 0.0 > Install Selection > Save and rebuild IDE > wait some minutes then your Lazarus will be restarted. Quote from: barracuda on August 16, 2023, 01:20:31 pmAlso the previous question was... what was wrong with my code. Which one? If you meant the TCDEdit error, you probably haven't installed the CustomDrawn package correctly. If you meant TImage.width=800 issue, the problem probably caused by  Image1.Align := alClient and/or Image1.Stretch  := True. Instead, you should disable the align and use StretchDraw command. You can learn how to use StretchDraw by looking into the demo CenterText.zip I posted recently. ----- I think the main problem you have is, you're doing thing the hard way. Lazarus can run on WinXP, Mint and many others. You don't need VirtualBox. Of course you can run Lazarus in a virtual machine, but you will have performance issue, unless you have a high-end machine with plenty of memory. Writing a text with transparent background is relatively easy. You can put a semi transparent rectangle + TLabel. But you tried to use a TEdit or CustomDrawn control or TJvMemo. You might succeed by using those components, but that will introduce many new problems. Try the CenterText demo I posted recently. That solves many of your problems. You can forget CustomDrawn, TJvMemo, etc. There you can learn how to draw a semi transparent rectangle, center text, stretching image, etc. ---------------------------------------------------------------------- barracuda · 2023-08-16 12:35 I cannot add memory to Windows XP, having 2.5GB. I will better close the Firefox to start Linux. It can be slow it I run both. The most stressing factor is when VMWare starts for no reason to open Browser in Windows XP (to open some url). This kills the memory because I cannot run WIN XP Firefox + VM with Firefox and Lazarus together. Do you see the Component of CustomDraw in Display/Components? I do not. I will check the thing you show me on screenshot, if I will find it. Edit: Using filter I have found only TCustomDrawGrid or CustomDrawGrid, not TCustomDraw ... I thought it will show me the components of TCD... Now I am reading I can install Lazarus on Windows. Windows XP? Really? "If you meant the TCDEdit error, you probably haven't installed the CustomDrawn package correctly." It did not restarted automatically. But after restart I still don't see it in components. I was trying TEdit or TCDEdit because I want to edit the title of the image manually just after viewing the image. Edit2: I see the TCustomDraw is ready for install, not installed. I dunno why it is not installed. I noticed it just now. ---------------------------------------------------------------------- Handoko · 2023-08-16 14:02 Done. 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, ExtCtrls, StdCtrls, LCLType; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Edit1: TEdit;    Image1: TImage;    procedure Button1Click(Sender: TObject);    procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure FormCreate(Sender: TObject);    procedure Image1DblClick(Sender: TObject);  private    Title: string;    Clickable: TRect;    procedure LoadImage;    procedure CalculateClickable;    procedure DrawCenterRectangle;    procedure WriteCenterText;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.LoadImage;const  ImageFile = 'img.png';var  Tmp: TPicture;begin  Image1.SetBounds(0, 0, Width, Height);  Image1.Picture.Clear;  Tmp := TPicture.Create;  try    Tmp.LoadFromFile(ImageFile);    Image1.Canvas.StretchDraw(ClientRect, Tmp.Bitmap);  finally    Tmp.Free;  end;end; procedure TForm1.CalculateClickable;var  W, H: Integer;begin  H := Image1.Canvas.TextHeight(Title);  W := Image1.Canvas.TextWidth(Title);  Clickable.Left   := (Width - W)  div 2;  Clickable.Top    := (Height - H) div 2;  Clickable.Width  := W;  Clickable.Height := H;  Clickable.Inflate(2, 0);end; procedure ChangeColor(var Data: Byte);const  Shift = 128; // 50% whitevar  Temp: Integer;begin  Temp := Data + Shift;  if (Temp > 255) then Temp := 255    else      if (Temp < 0) then Temp := 0;  Data := Temp;end; procedure TForm1.DrawCenterRectangle;const  BoxWidth  = 100;  BoxHeight = 20;var  ScanData:       PRGBQuad;  X, Y:           Integer;begin   // Draw semi transparent rectangle  Image1.Picture.Bitmap.BeginUpdate;  for Y := Clickable.Top to Clickable.Bottom do  begin    ScanData := Image1.Picture.Bitmap.ScanLine[Y];    for X:= 0 to (Image1.Picture.Bitmap.Width-1) do    begin      if (X >= Clickable.Left) then      begin        ChangeColor(ScanData^.rgbRed);        ChangeColor(ScanData^.rgbGreen);        ChangeColor(ScanData^.rgbBlue);      end;      Inc(ScanData);      if X >= Clickable.Right then Break;    end;  end;  Image1.Picture.Bitmap.EndUpdate; end; procedure TForm1.WriteCenterText;begin  Image1.Canvas.Brush.Style := bsClear;  Image1.Canvas.Font.Color  := clBlack;  Image1.Canvas.TextOut(Clickable.Left+2, Clickable.Top, Title);end; procedure TForm1.Button1Click(Sender: TObject);begin  LoadImage;  CalculateClickable;  DrawCenterRectangle;  WriteCenterText;end; procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  case Key of    VK_ESCAPE:      begin        Button1.Visible := True;        Edit1.Visible   := False;      end;    VK_RETURN:      begin        if Edit1.Text <> '' then        begin          Title := Edit1.Text;          CalculateClickable;          LoadImage;          CalculateClickable;        DrawCenterRectangle;          WriteCenterText;        end;      Button1.Visible := True;        Edit1.Visible   := False;      end;  end;end; procedure TForm1.FormCreate(Sender: TObject);begin  Title       := 'Double click here';  Edit1.Visible := False;end; procedure TForm1.Image1DblClick(Sender: TObject);var  MouseXY: TPoint;begin  MouseXY := ScreenToClient(Mouse.CursorPos);  if not(Clickable.Contains(MouseXY)) then Exit;  Button1.Visible := False;  Edit1.Left      := Clickable.Left;  Edit1.Top       := Clickable.Top;  Edit1.Width     := Clickable.Width;  Edit1.Text      := Title;  Edit1.Visible   := True;  Edit1.SetFocus;  Edit1.SelectAll;end; end. To make it easier to understand, I do not include the code for proportional stretching, I believe you can add it yourself. - Title (line #23) can be edited by double clicking the area defined by Clickable (line #24) - Stretching the image is done by the StretchDraw command, see line #51 - To change the position of the image (for example centering), you need to change the line #46 - To do proportional stretching, you need the change the Width and/or Height in the line #46 - To change the transparency of the rectangle, see line #72 - Double click the rectangle, a TEdit will appear, see line #160 - To conform the editing, press Enter, see line #137 ---------------------------------------------------------------------- KodeZwerg · 2023-08-16 15:43 This does not work on Windows. Quote from: Handoko on August 16, 2023, 04:02:08 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   H := Image1.Canvas.TextHeight(Title);  W := Image1.Canvas.TextWidth(Title);a quick fix: 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   Image1.Canvas.GetTextSize(Title, W, H); The rectangle drawing does not work either. No quick fix by me. When I make window bigger no rectangle(s) appear at all. ---------------------------------------------------------------------- barracuda · 2023-08-16 16:35 Quote from: KodeZwerg on August 16, 2023, 01:54:34 pmWhat is the benefit to run a virtual machine on a physical machine that is not good enough to run the virtual machine smooth? Why you make your work more complicated than it needed to be? Just install Lazarus with its cross compilers on your base machine and be happy using it without any lags or installation problems etc... ? My VM just crashed. I just stopped using Windows. I used it only for few programs. OK I can try it, but then it wont be able to work in Linux. So what's the point? My Images which I downloaded are on linux. My idea was to run the viewer and then for renaming to call a shell script. Why should I install these things on Windows when I try to learn linux and move to linux. So I installed linux and I have to start it to download images from Firefox and then to run the terminal, bash or commands, then I have to run the viewer and rename files. And yes, I will move the files to NTFS disks to free Home partion anyway, but I cannot work in Firefox on Win XP. ---------------------------------------------------------------------- Handoko · 2023-08-16 17:18 Thank you KodeZwerg for reporting the bugs. The bugs has been fixed in CenterText3. Tested on Ubuntu Mate 23.04 and Win7. Those issues were caused by how Windows and Linux treat PixelFormat. 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, ExtCtrls, StdCtrls, LCLType; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Edit1: TEdit;    Image1: TImage;    procedure Button1Click(Sender: TObject);    procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure FormCreate(Sender: TObject);    procedure Image1DblClick(Sender: TObject);  private    Title: string;    Clickable: TRect;    procedure LoadImage;    procedure CalculateClickable;    procedure DrawCenterRectangle;    procedure WriteCenterText;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.LoadImage;const  ImageFile = 'img.png';var  Tmp: TPicture;begin  Image1.SetBounds(0, 0, Width, Height);  Tmp := TPicture.Create;  try    Tmp.LoadFromFile(ImageFile);    Image1.Canvas.StretchDraw(ClientRect, Tmp.Bitmap);  finally    Tmp.Free;  end;end; procedure TForm1.CalculateClickable;var  W, H: Integer;begin  Image1.Canvas.GetTextSize(Title, W, H);  Clickable.Left   := (Width - W)  div 2;  Clickable.Top    := (Height - H) div 2;  Clickable.Width  := W;  Clickable.Height := H;  Clickable.Inflate(2, 0);end; procedure ChangeColor(var Data: Byte);const  Shift = 128; // 50% whitevar  Temp: Integer;begin  Temp := Data + Shift;  if (Temp > 255) then Temp := 255    else      if (Temp < 0) then Temp := 0;  Data := Temp;end; procedure TForm1.DrawCenterRectangle;const  BoxWidth  = 100;  BoxHeight = 20;var  ScanData:  Pointer;  Data24bit: PRGBTriple absolute ScanData;  Data32bit: PRGBQuad   absolute ScanData;  X, Y:     Integer;begin  Image1.Picture.Bitmap.BeginUpdate;  for Y := Clickable.Top to Clickable.Bottom do  begin{$ifdef Windows}  case Image1.Picture.Bitmap.PixelFormat of    pf24bit:      ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;    pf32bit:    ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;  end;{$endif}{$ifdef Linux}    ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 4;{$endif}    for X:= 0 to Clickable.Width do    begin      case Image1.Picture.Bitmap.PixelFormat of        pf24bit:          begin          begin              ChangeColor(Data24bit^.rgbtRed);            ChangeColor(Data24bit^.rgbtGreen);              ChangeColor(Data24bit^.rgbtBlue);            end;{$ifdef Windows}          Inc(ScanData, 3);{$endif}{$ifdef Linux}            Inc(ScanData, 4);{$endif}          end;        pf32bit:          begin            begin              ChangeColor(Data32bit^.rgbRed);              ChangeColor(Data32bit^.rgbGreen);              ChangeColor(Data32bit^.rgbBlue);            end;            Inc(ScanData, 4);          end;      end;    end;  end;  Image1.Picture.Bitmap.EndUpdate;end; procedure TForm1.WriteCenterText;begin  Image1.Canvas.Brush.Style := bsClear;  Image1.Canvas.Font.Color  := clBlack;  Image1.Canvas.TextOut(Clickable.Left+2, Clickable.Top, Title);end; procedure TForm1.Button1Click(Sender: TObject);begin  LoadImage;  CalculateClickable;  DrawCenterRectangle;  WriteCenterText;end; procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  case Key of    VK_ESCAPE:      begin        Button1.Visible := True;        Edit1.Visible   := False;      end;    VK_RETURN:      begin        if Edit1.Text <> '' then        begin          Title := Edit1.Text;          CalculateClickable;          LoadImage;          CalculateClickable;        DrawCenterRectangle;          WriteCenterText;        end;      Button1.Visible := True;        Edit1.Visible   := False;      end;  end;end; procedure TForm1.FormCreate(Sender: TObject);begin  Title       := 'Double click here';  Edit1.Visible := False;end; procedure TForm1.Image1DblClick(Sender: TObject);var  MouseXY: TPoint;begin  MouseXY := ScreenToClient(Mouse.CursorPos);  if not(Clickable.Contains(MouseXY)) then Exit;  Button1.Visible := False;  Edit1.Left      := Clickable.Left;  Edit1.Top       := Clickable.Top;  Edit1.Width     := Clickable.Width;  Edit1.Text      := Title;  Edit1.Visible   := True;  Edit1.SetFocus;  Edit1.SelectAll;end; end. - Title (line #23) can be edited by double clicking the area defined by Clickable (line #24) - Stretching the image is done by the StretchDraw command, see line #50 - To change the position of the image (for example centering), you need to change the line #46 - To do proportional stretching, you need the change the Width and/or Height in the line #46 - To change the transparency of the rectangle, see line #70 - Double click the rectangle, a TEdit will appear, see line #184 - To conform the editing, press Enter, see line #161 Bug fixes: - Line #60, suggested by KodeZwerg to make it runs correctly on Windows - Line #94..104, Linux always uses 4 bytes per pixel for StretchDrawed images even on pf24bit - Line #115..120, Linux always uses 4 bytes per pixel for StretchDrawed images even on pf24bit ~edit~ Line #99 should be:  ...  + Clickable.Left * 4; ---------------------------------------------------------------------- barracuda · 2023-08-16 17:39 So on WinXP, the Lazarus 2.2.6 installed. I found the Debugger config on C: and fpc config on P: but the problem is that the Lazarus reports the the fpc config is missing. It is not. It is there with the fpc.exe in correct directory where is Lazarus installed. QuoteOn Win XP I've installed Lazarus 2.2.6 fpc 3.2.2. I got some errors missing configuration file for fpc. A project is using target OS=win32 and CPU=i386 system.ppu for this system was not found in folder bin of fpc. Make sure fpc is correctly install for this target and that fpc.cfg contains correct directories. Next error is Cannot find component TACSVolueQuery. Its not registered with RegisterClass and lfm file not found. This is needed by unit ... some path out of Lazarus install folder, some audio demo program. Next problem is I need to configure it to black background. ---------------------------------------------------------------------- barracuda · 2023-08-18 08:03 Now I have tested your programs. Thank you. Now I see that the function ChangeColor may not be declared. Interesting. I thought functions must be declared or have return type. I see one problem. This is logical and can be expected with semitransparent background. Can we detect the average lightness of the background? While we are in the loop, there could be one more function to detect it the background of image under the rectangle of edit control is dark or light. So we would have some options what to do with the colors. Because if the area is really black we don't need to add extra background to the edit control. We just set the text color to black. If the average color in area is white, we can set the text to black. But if there is low contrast, then we could add the background color to the edit box, and choose the color depending if it is darker or lighter. ---------------------------------------------------------------------- Handoko · 2023-08-18 08:58 Quote from: barracuda on August 18, 2023, 10:03:33 amCan we detect the average lightness of the background? While we are in the loop, there could be one more function to detect it the background of image under the rectangle of edit control is dark or light. Sure we can. That code works by doing 2 main loops. The first is looping the Y coordinate of the pixels (see line #92), by using the ScanLine[Y] command you set the pointer to point to the first left most pixel. The result there then added with X multiple by 3 or 4, depends on the pixel format of the image. The second is looping the X coordinate of the pixels (see line #105). So now the Data24bit^ or Data32bit^ (depends on the pixel format) will point to the pixel information. By setting the pointer to point to the correct X, Y position, now you can read the pixel information, which are the values of red, green, blue and alpha (transparency) of the pixel. And if you modify the value, for example by adding it with 128 (as shown in the demo, line 74), it will increase the brightness of the pixel. That's how it draws a semi transparent rectangle. So if you do the looping from top to bottom and left to right of all the pixels, and averaging all the r, g, b values you can get the global lightness of the image. Quote from: barracuda on August 18, 2023, 10:03:33 am... expected with semitransparent background. For detecting semi transparent pixel, you can learn from this demo: https://forum.lazarus.freepascal.org/index.php/topic,37242.msg488758.h tml#msg488758 --- Basically, the method I used is relatively simple. But the hardest part is, we need to deal with the pixel format. Each image file format (jpg, png, bmp, etc) has different pixel formats. And Linux and Windows handle pixel format a bit differently. ---------------------------------------------------------------------- barracuda · 2023-08-18 09:15 My try to get the avarage intensity (of grayscale bitmap under the edit control). Please check if I do it correctly. 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 procedure TForm1.GetAvgIntensity;const  BoxWidth  = 100;  BoxHeight = 20;var  ScanData:  Pointer;  Data24bit: PRGBTriple absolute ScanData;  Data32bit: PRGBQuad   absolute ScanData;  X, Y:       Integer;  temp: Integer;begin  temp := 125;  AvgInt := 125;  for Y := Clickable.Top to Clickable.Bottom do  begin{$ifdef Windows}  case Image1.Picture.Bitmap.PixelFormat of    pf24bit:      ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;    pf32bit:    ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;  end;{$endif}{$ifdef Linux}    ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 4;{$endif}    for X:= 0 to Clickable.Width do    begin      case Image1.Picture.Bitmap.PixelFormat of        pf24bit:          begin          temp := round(Data24bit^.rgbtRed + Data24bit^.rgbtGreen + Data24bit^.rgbtBlue) div 3;            AvgInt := (AvgInt+temp) div 2;{$ifdef Windows}            Inc(ScanData, 3);{$endif}{$ifdef Linux}            Inc(ScanData, 4);{$endif}          end;        pf32bit:        begin            temp := round(Data24bit^.rgbtRed + Data24bit^.rgbtGreen + Data24bit^.rgbtBlue) div 3;            AvgInt := (AvgInt+temp) div 2;            Inc(ScanData, 4);          end;    end;    end;  end;end; ---------------------------------------------------------------------- Handoko · 2023-08-18 09:55 Your code has some issues: Line 14, you should loop from 0 to the height of the image. Line 16..24, no need to include the clickable because you start from left most position. Line 27, you should loop from 0 to the width of the image. And you average calculation is incorrect. ---------------------------------------------------------------------- Handoko · 2023-08-18 09:58 I modified your code and added it to this demo. This demo is quickly tested on Linux only. It may have bugs. 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, ExtCtrls, StdCtrls, LCLType; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Edit1: TEdit;    Image1: TImage;    procedure Button1Click(Sender: TObject);    procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure FormCreate(Sender: TObject);    procedure Image1DblClick(Sender: TObject);  private    Title: string;    Clickable: TRect;    procedure LoadImage;    procedure CalculateClickable;    procedure DrawCenterRectangle;    procedure WriteCenterText;    procedure GetAvgIntensity;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.LoadImage;const  ImageFile = 'img.png';var  Tmp: TPicture;begin  Image1.SetBounds(0, 0, Width, Height);  Tmp := TPicture.Create;  try    Tmp.LoadFromFile(ImageFile);    Image1.Canvas.StretchDraw(ClientRect, Tmp.Bitmap);  finally    Tmp.Free;  end;end; procedure TForm1.CalculateClickable;var  W, H: Integer;begin  Image1.Canvas.GetTextSize(Title, W, H);  Clickable.Left   := (Width - W)  div 2;  Clickable.Top    := (Height - H) div 2;  Clickable.Width  := W;  Clickable.Height := H;  Clickable.Inflate(2, 0);end; procedure ChangeColor(var Data: Byte);const  Shift = 128; // 50% whitevar  Temp: Integer;begin  Temp := Data + Shift;  if (Temp > 255) then Temp := 255    else      if (Temp < 0) then Temp := 0;  Data := Temp;end; procedure TForm1.DrawCenterRectangle;const  BoxWidth  = 100;  BoxHeight = 20;var  ScanData:  Pointer;  Data24bit: PRGBTriple absolute ScanData;  Data32bit: PRGBQuad   absolute ScanData;  X, Y:     Integer;begin  Image1.Picture.Bitmap.BeginUpdate;  for Y := Clickable.Top to Clickable.Bottom do  begin{$ifdef Windows}  case Image1.Picture.Bitmap.PixelFormat of    pf24bit:      ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;    pf32bit:    ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;  end;{$endif}{$ifdef Linux}    ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 4;{$endif}    for X:= 0 to Clickable.Width do    begin      case Image1.Picture.Bitmap.PixelFormat of        pf24bit:          begin          begin              ChangeColor(Data24bit^.rgbtRed);            ChangeColor(Data24bit^.rgbtGreen);              ChangeColor(Data24bit^.rgbtBlue);            end;{$ifdef Windows}          Inc(ScanData, 3);{$endif}{$ifdef Linux}            Inc(ScanData, 4);{$endif}          end;        pf32bit:          begin            begin              ChangeColor(Data32bit^.rgbRed);              ChangeColor(Data32bit^.rgbGreen);              ChangeColor(Data32bit^.rgbBlue);            end;            Inc(ScanData, 4);          end;      end;    end;  end;  Image1.Picture.Bitmap.EndUpdate;end; procedure TForm1.WriteCenterText;begin  Image1.Canvas.Brush.Style := bsClear;  Image1.Canvas.Font.Color  := clBlack;  Image1.Canvas.TextOut(Clickable.Left+2, Clickable.Top, Title);end; procedure TForm1.GetAvgIntensity;var  ScanData:  Pointer;  Data24bit: PRGBTriple absolute ScanData;  Data32bit: PRGBQuad   absolute ScanData;  X, Y:      Integer;  AvgInt:    Integer;  Total:   Integer;  Temp:      Integer;begin  Total := 0;  for Y := 0 to Image1.Picture.Bitmap.Height-1 do  begin    ScanData := Image1.Picture.Bitmap.ScanLine[Y];    for X:= 0 to Image1.Picture.Bitmap.Width-1 do    begin      case Image1.Picture.Bitmap.PixelFormat of        pf24bit:          begin          Temp  := (Data24bit^.rgbtRed + Data24bit^.rgbtGreen + Data24bit^.rgbtBlue) div 3;            Total := Total + Temp;{$ifdef Windows}            Inc(ScanData, 3);{$endif}{$ifdef Linux}          Inc(ScanData, 4);{$endif}          end;        pf32bit:          begin            Temp  := (Data32bit^.rgbRed + Data32bit^.rgbGreen + Data32bit^.rgbBlue) div 3;            Total := Total + Temp;          Inc(ScanData, 4);          end;      end;    end;  end;  AvgInt  := R ound(Total/(Image1.Picture.Bitmap.Width*Image1.Picture.Bitmap.Height)) ;  Caption := AvgInt.ToString;end; procedure TForm1.Button1Click(Sender: TObject);begin  LoadImage;  CalculateClickable;  DrawCenterRectangle;  WriteCenterText;  GetAvgIntensity;end; procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  case Key of    VK_ESCAPE:      begin        Button1.Visible := True;        Edit1.Visible   := False;      end;    VK_RETURN:      begin        if Edit1.Text <> '' then        begin          Title := Edit1.Text;          CalculateClickable;          LoadImage;          CalculateClickable;        DrawCenterRectangle;          WriteCenterText;        end;      Button1.Visible := True;        Edit1.Visible   := False;      end;  end;end; procedure TForm1.FormCreate(Sender: TObject);begin  Title       := 'Double click here';  Edit1.Visible := False;end; procedure TForm1.Image1DblClick(Sender: TObject);var  MouseXY: TPoint;begin  MouseXY := ScreenToClient(Mouse.CursorPos);  if not(Clickable.Contains(MouseXY)) then Exit;  Button1.Visible := False;  Edit1.Left      := Clickable.Left;  Edit1.Top       := Clickable.Top;  Edit1.Width     := Clickable.Width;  Edit1.Text      := Title;  Edit1.Visible   := True;  Edit1.SetFocus;  Edit1.SelectAll;end; end. The result is shown on the titlebar. As you can see from the screenshot below, the value is 65, which means the picture is relatively dark. The values can start from 0 to 255. Value of 128 means 50% brightness. ---------------------------------------------------------------------- barracuda · 2023-08-18 10:05 No no no. We don't want avg intensity from all the image but only from the area where the text will be present. ---------------------------------------------------------------------- Handoko · 2023-08-18 10:07 Then, you put the Clickable area calculation back to the code. For the average calculation, it will be easier done by totaling all the values then divided by the count of total pixels. In my case: Avg = Total / (...bitmap.Width * ...bitmap.Height) You need to change the width and height. ---------------------------------------------------------------------- barracuda · 2023-08-18 10:19 Then the avg. intensity should be // begin of loop sum := sum + Data24bit^.rgbtRed + Data24bit^.rgbtGreen + Data24bit^.rgbtBlue; // end of loop avg := sum div ( (Clickable.Width div Clickable.Height) div 3); I modified my previous description. I don't speak about color. ---------------------------------------------------------------------- Handoko · 2023-08-18 10:46 Oops, I forgot to mention the pixel color need to be divided by 3, but it's already done in the code: Temp  := (Data24bit^.rgbtRed + Data24bit^.rgbtGreen + Data24bit^.rgbtBlue) div 3; Temp  := (Data32bit^.rgbRed + Data32bit^.rgbGreen + Data32bit^.rgbBlue) div 3; ---------------------------------------------------------------------- barracuda · 2023-08-18 11:47 I have prepared this so far... 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 type  TColIndicator = (very_dark, medium_dark, normal_intensity, medium_light, very_light);   private    AvgInt: Integer;    FontColor, BgColor: TColor;    ColIndicator: TColIndicator;    procedure GetAvgIntensity;    procedure SetColors; procedure TForm1.GetAvgIntensity;const  BoxWidth  = 100;  BoxHeight = 20;var  ScanData:  Pointer;  Data24bit: PRGBTriple absolute ScanData;  Data32bit: PRGBQuad   absolute ScanData;  X, Y:       Integer;  sum: Integer;begin  for Y := Clickable.Top to Clickable.Bottom do  begin{$ifdef Windows}  case Image1.Picture.Bitmap.PixelFormat of    pf24bit:      ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;    pf32bit:      ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 3;  end;{$endif}{$ifdef Linux}    ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 4;{$endif}    for X:= 0 to Clickable.Width do    begin      case Image1.Picture.Bitmap.PixelFormat of        pf24bit:          begin          sum := sum + Data24bit^.rgbtRed + Data24bit^.rgbtGreen + Data24bit^.rgbtBlue;{$ifdef Windows}            Inc(ScanData, 3);{$endif}{$ifdef Linux}            Inc(ScanData, 4);{$endif}        end;        pf32bit:          begin            sum := sum + Data24bit^.rgbtRed + Data24bit^.rgbtGreen + Data24bit^.rgbtBlue;          Inc(ScanData, 4);          end;      end;    end;  end;  AvgInt := sum div ( (Clickable.Width div Clickable.Height) div 3);end; procedure TForm1.SetColors;begin  if AvgInt<64) then    begin      ColIndicator:=very_dark;      FontColor:=White;    end  else if AvgInt<100 then     begin       ColIndicator:=medium_dark;       FontColor:=White;       BgColor:=Black;     end  else if AvgInt>190 then    begin      ColIndicator:=very_light;      FontColor:=Black;  end  else if AvgInt>154 then    begin      ColIndicator:=medium_light;      FontColor:=Black;      BgColor:=White;    end  else    begin      ColIndicator:=normal_intensity;      FontColor:=Black;      BgColor:=White;    end;end; procedure TForm1.Button1Click(Sender: TObject);begin  LoadImage;  CalculateClickable;  GetAvgIntensity;  SetColors;  DrawCenterRectangle;  WriteCenterText;end; ---------------------------------------------------------------------- Handoko · 2023-08-18 12:04 That seems good. But maybe you miss it, I ever mentioned there was a mistake in my code. In your code above, in GetAvgIntensity line #29, that should be: ScanData := Image1.Picture.Bitmap.ScanLine[Y] + Clickable.Left * 4; For pf32bit, it should be 4 bytes. That's why it should be multiplied by 4. For pf24bit, it should be 3 bytes. That's why it should be multiplied by 3. (But things go weird, on Linux it should always be 4) ---------------------------------------------------------------------- barracuda · 2023-08-18 12:48 Why linux reads 4 bytes with pf24bit format? ---------------------------------------------------------------------- Handoko · 2023-08-18 12:55 I don't know. But I tested several times and I found, in Linux: - It normally will read 3 bytes for pf24bit format - But if the image is StretchDrawed, it will store/read 4 bytes for pf24bit format That's why you can see I used many conditional compiler directives in the demos to make to code work correctly on both Windows and Linux. If you can afford it, you should buy a new computer so you will have both Windows and Linux computers to test your programs. Or at least you should have a good computer with plenty of RAM so you can run tests on virtual machines. ---------------------------------------------------------------------- KodeZwerg · 2023-08-18 14:09 Handoko, I have two thinkings about your drawn color calculated rectangle: both have in common: get absolute screen coordinates from your calculated destination rectangle (ClientToScreen) prepare to make a snapshot of that small area Idea 1: grayscale it and paint text over Idea 2: inverse it and paint text over apply the small bitmap onto the image, done (both ways can be done via the canvas copymode IIRC) Additional, stop using SetBounds() and just activate from image alClient alignment and stretch property. On windows your current way will come more and more worse when you change window size, and at a certain size (ie: maximized) your code break with access violations. ---------------------------------------------------------------------- barracuda · 2023-08-18 15:26 Now it can detect the color and the program decides wheather to use background color and what color to use. Now please advice, how to get 1st argument of program or how to parse arguments. I have a script in bash which will send list of files like "file 1.jpg" "bla bla.jpg" "next file of mine.jpg" This is ordered list and I need to move it to TStringList. So I will call the program like so: One set of images: project1.exe "file 1.jpg" "bla bla.jpg" "next file of mine.jpg" & Second set of images: project1.exe "very dark 1.jpg" "darker 2.jpg" "normal brightness 3.jpg" "lighter 4.jpg" "very light 5.jpg" & For testing purposes we may have like 5 files of img1.png to img5.png with different level of brightness. I have another idea. May be good to create an icon on the left, which will represent the first set of images. Let's say the icon could be like 64x64px. And after the second call it will create next icon under the first icon, so we have two icons with - two TStrings of list. So acctually this would need and array of TString list. Icon should be created from the first image. And the image is always square, so we expect that there will be enough room on the left side and right side for the icons. And I expect the icons should be clickable like buttons are so when we will click one icon, we will watch only that set of images. Notice that the main point is that the program is called from script which defines the order of images. The program does not do any filtering. ---------------------------------------------------------------------- Handoko · 2023-08-18 16:48 Quote from: KodeZwerg on August 18, 2023, 04:09:57 pmAdditional, stop using SetBounds() and just activate from image alClient alignment and stretch property. Originally, I used alClient. You can see it in my very first demo. Unfortunately OP has problem to understand why the loaded image would automatically fit to the screen height and the width and height of the image didn't go as what he thought they should be. I know why but my English is limited I couldn't explain it to him. Instead, I wrote a new demo without set the alignment and use StretchDraw. https://forum.lazarus.freepascal.org/index.php/topic,64159.msg488538.h tml#msg488538 Quote from: barracuda on August 18, 2023, 05:26:08 pmNow please advice, how to get 1st argument of program or how to parse arguments. To read the command line parameters (or what you called arguments), you can use ParamCount and ParamStr command. You can learn how to use it in my very first demo, line #161, #165 and #171: https://forum.lazarus.freepascal.org/index.php/topic,64159.msg488251.h tml#msg488251 ---------------------------------------------------------------------- barracuda · 2023-08-18 17:36 Quote from: Handoko on August 18, 2023, 06:48:37 pmQuote from: KodeZwerg on August 18, 2023, 04:09:57 pmAdditional, stop using SetBounds() and just activate from image alClient alignment and stretch property. Originally, I used alClient. You can see it in my very first demo. Unfortunately OP has problem to understand why the loaded image would automatically fit to the screen height and the width and height of the image didn't go as what he thought they should be. I know why but my English is limited I couldn't explain it to him. Instead, I wrote a new demo without set the alignment and use StretchDraw. https://forum.lazarus.freepascal.org/index.php/topic,64159.msg488538.h tml#msg488538 Thanks for reminding. I wanted to ask you if is there anywhere in the component saved current width and height of the displayed image, not the original. I know that we basicely know this value on the begin of the program when we use setbounds. ---------------------------------------------------------------------- KodeZwerg · 2023-08-18 18:00 I admit, I didn't read whole thread about a linux topic Sorry Handoko @barr: If not already said, you have two different things, the component "TImage" wich has its Clientarea and inside you have a "TPicture" container that holds the original image.... so "current width and height of the displayed image, not the original" is a very confusing text to me. When you talk about the window, than refer to TImage root properties, when you talk about the image itself, refer to TPicture properties. Scaling stretching etc is done automatic if enabled but the "original" is always "original" (if you was paying attention, that goes to TPicture) @Handoko, what do you think about my suggestion to simplify that "graphical edit" by using a snapshot and merging it in? ---------------------------------------------------------------------- barracuda · 2023-08-18 18:04 Where do you save input parameters in project options? ---------------------------------------------------------------------- KodeZwerg · 2023-08-18 18:18 Quote from: barracuda on August 18, 2023, 08:04:45 pmWhere do you save input parameters in project options?If you mean to simulate command line arguments as parameters, Menu Run -> Run Parameters ... -> Commandline Parameters As a test, here is a quicky: 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 procedure TForm1.FormCreate(Sender: TObject);var  i: Integer;begin  Memo1.Lines.BeginUpdate;  Memo1.Clear;  for i := 0 to ParamCount do  Memo1.Lines.Add(Format('Parameter #%d: %s', [i, ParamStr(i)]));  Memo1.Lines.EndUpdate;end;This will end in whats shown on picture 2 ---------------------------------------------------------------------- barracuda · 2023-08-18 18:32 Thank you. Am I doing something wrong that I cannot see value of ParamCount ParamStr(1) Unfortunately I am unable to switch to English. I tried to enable it but it is still in local language. I installed English. Strange. So I tried to break and step in ParseParams and then to add a watch through Debug menu but I got identifier not found. ---------------------------------------------------------------------- KodeZwerg · 2023-08-18 19:05 I do not know what language you are using but "ParamCount" and its "ParamStr" method names are everywhere same AFAIK, it is loaded and filled automagical inside the system unit for global usage. I attached the above demo, open the "project1.lpi" file, all my settings are stored within this project, run it, what does it show? ---------------------------------------------------------------------- barracuda · 2023-08-19 09:13 Regardless ParamStr or ParamCount. During Debuging step by step, I need to check the value of the result or expression: "length(filePath)" in code: 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 s0:=copy(ParamStr(i),length(filePath),999)I cannot. In Delphi no problem with this. Here I am trying to set s0 to basename. Also I tried this: 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 s0:=copy(ParamStr(i),length(filePath))And doesn't work like I expected that it could return the basename. ---------------------------------------------------------------------- KodeZwerg · 2023-08-19 10:14 ParamStr(0) is always the full qualified string for exemplary "X:\YourPath\YourApp.exe" in Delphi or Lazarus/FreePascal. We can not mindread.... "filePath" is neither in FreePascal nor in Delphi a default common global, show complete that we understand you. Maybe you just do not know how to debug step by step? Maybe you just do not know that you can set watches on values for easier checking? Maybe you just do not know that there is a ExtractFileName() method that can be freely used? Maybe you just do not supply full information so nobody can guess what you actual try doing? ---------------------------------------------------------------------- barracuda · 2023-08-19 10:40 Quote from: KodeZwerg on August 19, 2023, 12:14:50 pmMaybe you just do not know how to debug step by step?I do step by step debugging. Quote from: KodeZwerg link=topic=64159.msg489037#msg489037 Maybe you just do not know that you can set watches on values for easier checking? [/quoteI tell, you this does not show the evaluated values of funtions. I can do this in Delphi no problem. But in Lazarus is typical "identifier not found". That's why I don't see result of the length function. QuoteMaybe you just do not know that there is a ExtractFileName() method that can be freely used?I looked for basename(). But anyway why to extract information which is already known from the variable? 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 filePath := ExtractFilePath(ParamStr(i)); It's always hard decision for me because I prefer low level programming. So even with the function ExtractFilename ... this doesn't solve the current problem what I am trying to learn. Using ExtractFilename can be fast solution, which skips the need to learn how to use length function and watch expression during debugging. You can provide alternative solution, but I need to learn that little point anyway to be more indepentent on help of others. I am almost finished with param parsing so I will show you the code a little bit later. Now waiting for response and have to have a break. * * * Note: I see I need to parse arguments in different way 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 procedure TForm1.ParseParams;var  i: Integer;  Params: array of string;begin  if ParamCount <= 0 then Exit;   SetLength(Params, ParamCount);   // copy parameters to dynamic artray  for i := 1 to ParamCount do    Params[i - 1] := ParamStr(i);* * * And I need to change the way I process arguments. I will use ChatGPT advice. You are absolutely correct. In FreePascal and its Run-Time Library (RTL), there is a function that allows you to remove the first element from an array similar to array_shift in PHP. This function is called Delete and is located in the SysUtils unit. Here's an example of how you can use it: 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 uses  SysUtils; procedure TForm1.ParseParams;var  i: Integer;  Params: array of string;begin  if ParamCount <= 0 then Exit;   SetLength(Params, ParamCount);  for i := 1 to ParamCount do    Params[i - 1] := ParamStr(i);   // Removing the first element from the array  if Length(Params) > 0 then    Delete(Params, 0, 1);   // Displaying the remaining elements in the array  for i := 0 to High(Params) do    Memo1.Lines.Add('Param ' + IntToStr(i) + ': ' + Params[i]);end;  Yet I would like to call the program repetitively like so: program name "My 1st Gallery" ... argument list of images... & program name "My 2nd Gallery" ... next images & program save "My Saturday Galeries" & program exit & // Program exited. // Galeries saved. Let's read them to view the save images: program read "My Saturday Galeries" & program exit & To add the icons and information to the existing instance of the program running in memory. Because I don't know how technically to solve that I asked of chatGPT, so you please tell me if this code it suggested is not just ton of ballshit: 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 uses  SysUtils, SyncObjs, Windows; type  TSharedData = record    // You can add data here that you want to share between instances  end; var  Mutex: TMutex;  SharedData: ^TSharedData;  Created: Boolean; procedure InitializeSharedMemory;begin  Mutex := TMutex.Create(nil, False, 'MySharedMemoryMutex');  Mutex.Acquire;   Created := False;  SharedData := MapViewOfFile(    CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, SizeOf(TSharedData), 'MySharedMemory'),    FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TSharedData)  );   if SharedData = nil then  begin    Writeln('Could not create or access shared memory.');    Exit;  end;   if GetLastError = ERROR_ALREADY_EXISTS then    Created := True  else  FillChar(SharedData^, SizeOf(TSharedData), 0);   Mutex.Release;end; procedure SendDataToExistingInstance;begin  Mutex.Acquire;   // Here you can update data in the shared memory  // or send a message to the existing instance   Mutex.Release;end; begin  InitializeSharedMemory;   if Created then  begin    // This is a new instance, perform normal operations  end  else  begin    // This is an already existing instance, perform communication    SendDataToExistingInstance;  end;   // Release the shared memory and mutex  UnmapViewOfFile(SharedData);  Mutex.Free;end. * * * I plan to write ini file to save settings. I think I will include this as a separate unit. See attachment. ---------------------------------------------------------------------- barracuda · 2024-04-28 12:14 Quote from: Handoko on August 03, 2023, 02:36:07 pmI can see your issue now. Unfortunately I don't know what causes it. My guesses, maybe the font files were damaged or maybe you need to reinstall your Lazarus. I saw you're using older version of Lazarus installed using your OS software manager. Don't use that. You should use the latest version provided by official Lazarus team, here: https://sourceforge.net/projects/lazarus/files/ I think before you reinstall the Lazarus, you may need to do a complete Lazarus/FPC removal: https://forum.lazarus.freepascal.org/index.php/topic,38828.msg265293.h tml#msg265293 I don't know why you want to use CodeTyphon. I and many users here do not use CodeTyphon, you should ask your CodeTyphon issue on their forum. Hello, I am on Mint 21.3 (I think it was 1st beta version) now x64 notebook. Can I install FPC and Freelazarus from Repo? It is long time I was using Lazarus so did I forget something? 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 sudo apt install fp-compiler-3.2.2  Or should I install newer version? ---------------------------------------------------------------------- Thaddy · 2024-04-28 12:49 sudo apt update sudo apt install fpc sudo apt install lazarus Will install fpc 3.2 and laz 3.0 ---------------------------------------------------------------------- barracuda · 2024-04-28 13:50 It did not help (FPC is OK, Lazarus old version) and I cannot remove it now 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 sudo dpkg -r --force-all lazarus-src-2.2error: lazarus-src-2.2  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 apt remove lazarus-src-2.2Removing lazarus-src-2.2 (2.2.0+dfsg1-5ubuntu1) …dpkg- divert: error: file name „do“ not absolutetoo many errors Sub-process /usr/bin/dpkg returned an error code (1) ---------------------------------------------------------------------- Thaddy · 2024-04-28 15:13 sudo apt purge lazarus sudo apt autoremove Removes lazarus. Strange that mint is behind Debian, though. You can then build lazarus from source by downloading stable from gitlab and do make bigide. You may want to add backports to Mint, then you will get lazarus 3.0 when you do sudo apt install lazarus. ---------------------------------------------------------------------- barracuda · 2024-04-28 16:54 but all tries to remove/purge/autoremove etc. give the same error code 1, name of do file is not absolute I try this... 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 sudo apt install --fix-broken lazarus-src-2.2  the is the error here not "do" (local lang.) but "to" (English). https://askubuntu.com/questions/1471839/error-while-removing-package- lazarus-src-2-2-dpkg-divert-error-file-name-to I was so lucky to remove it using this script by Jim: 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 #!/bin/bash # Get a list of diversions with pathsdiversions=$(dpkg- divert --list 'lazarus*') # Split the output into stringsIFS=$'\n' # Passing through each line of outputfor line in $diversions; do  # Extract the path from the line  path=$(echo "$line" | awk '{print $2}')   # Execute the command with the path substituted  sudo dpkg- divert --remove --no-rename "$path" #Remove the rest of the garbagesudo apt-get install -fsudo apt autoremove doneIt's recommended to save it for later use. Removing took two hours of pressing y.