Load tiles into TImageList at runtime lazarus / 31-LCL ---------------------------------------------------------------------- _N_ · 2021-06-25 11:32 Hello. Sorry for a silly question, but I am not sure that I go into right direction. I have a dozen of png files (some are with transparent background that I need to keep) and each of them contains several (well, form 2 to a few hundreds) square tiles. Tile size differs from file to file. My task is to load them at runtime and then display on a form (like a tile map editor). To simplify tiles loading I decided to use TImageList. It is easy to use visual component to load tiles from a file: just set tile size and click on "Add" button. But how can I do this from 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 Tiles1 := TImageList.Create(nil);Tiles1.Width := 32;Tiles1.Height := 32;Tiles1. // <- I failed to find a method that will split a big image Another thing is that sometimes I'd like to join images from several source files into single image list (tile size are identical). Unfortunately I wasn't lucky googling the solution... Also I am not sure if using TImageList is a correct way to go... I am not asking for full implementation (however code snippet would be appreciated). I'd like to know the idea, correct way of solving of such task and a hint which methods I should use (full list of TImageList methods didn't give me a clue other than reading a big image and redrawing parts into separate slots - but I feel such approach is not optimal). Thank you for the help. ---------------------------------------------------------------------- loaded · 2021-06-25 12:43 Hi, it's easy to view and combine tile-shaped images. First you need to set the dimensions of your current drawing area, then calculate which tile should be placed where. This requires some math. In my opinion, the best method for this job is to use the Image object. With this method, I can create 25000*25000 images. 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.Button1Click(Sender: TObject);var  mtile:TPicture;begin  mtile:=TPicture.Create;  mtile.LoadFromFile('D:\example.png');  image1.Picture:=nil;  image1.Picture.Bitmap.SetSize(mtile.Width*2,mtile.Height);  image1.Canvas.Draw(0,0,mtile.Bitmap);  image1.Canvas.Draw(mtile.Width,0,mtile.Bitmap);end; ---------------------------------------------------------------------- lucamar · 2021-06-25 12:58 TImageList loads its data from TBitmaps or TIcons using any of its Add* or Insert* methods: Add, AddSliced, AddSlices, AddIcon, etc. All you have to do is to create a TBitmap, load the image(s) and use the proper method of the image list to add it (them) to it. ---------------------------------------------------------------------- wp · 2021-06-25 14:16 Quote from: _N_ on June 25, 2021, 01:32:34 pmHello. 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 Tiles1. // <- I failed to find a method that will split a big image You probably mean the AddSliced method, it has the horizontal and vertical count of images as parameters. See the attached demo. It uses one of the VirtualTreeView image stripes (25 images wide, 1 image high) and loads it into a TImageList. Using the scrollbar you can display all the generated images. The "Merge" button creates another tiled images, now 5x5 images. ---------------------------------------------------------------------- _N_ · 2021-06-28 08:46 Thank you all @loaded, @lucamar, @wp. From each of the answers I've got something useful. Indeed, AddSliced method was what I searched for. However, I didn't have it on Lazarus 1.8.2, but when upgraded to Lazarus 2.0.6 - it is there and works. Here is simple code to solve the issue: 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.Button1Click(Sender: TObject);const  TILE_SIZE = 32;var  TilesImage: TCustomBitmap;  TilesList: TImageList;begin  TilesImage := TPortableNetworkGraphic.Create();  try    TilesImage.LoadFromFile('laz_vt_check_dark_200.png');     TilesList := TImageList.Create(nil);    TilesList.Width := TILE_SIZE;    TilesList.Height := TILE_SIZE;    TilesList.AddSliced(TilesImage, TilesImage.Width div TILE_SIZE, TilesImage.Height div TILE_SIZE);  finally    TilesImage.Free();  end;   TilesList.Draw(Image1.Canvas, 0, 0, 2);  TilesList.Draw(Image1.Canvas, TILE_SIZE, 0, 8);  TilesList.Draw(Image1.Canvas, 0, TILE_SIZE, 16);  TilesList.Draw(Image1.Canvas, TILE_SIZE, TILE_SIZE, 24);  TilesList.Free();end;