array of uint32 to TImage [SOLVED] lazarus / 39-Graphics ---------------------------------------------------------------------- rforcen · 2022-01-28 09:06 how can i directly convert an array of uint32 to a TImage without cycling with a SetPixel(x,y,color) ? i've coded a sample loop solution using fpimage: EDIT: i've used this to write a jpeg file of a mandelbrot fractal, complete code @ https://github.com/rforcen/fpc/tree/main/mandel 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 {$mode objfpc}{$h+}program Prog_au32totimage; uses classes, sysutils,     FPImage, FPWriteJPEG; var   au32 : array of uint32;  w,h: integer;  i: integer; // function au32ToImage(au32:array of uint32; w,h:integer) : TFPMemoryImage;var   i,j : integer;  pix : uint32;  col : TFPColor; // rgba in 0..$ffff range -> (0..$ff) << 8begin  au32ToImage := TFPMemoryImage.Create(w,h);   for i:=0 to w-1 do    for j:=0 to h-1 do begin      pix:=au32[i*w + j];      with col do begin        red:=(pix and $FF) shl 8;         green:=((pix shr 8) and $FF) shl 8;         blue:=((pix shr 16) and $FF) shl 8;         alpha:=((pix shr 24) and $FF) shl 8;      end;      au32ToImage.Colors[i, j] := col;    end;end; //procedure au32ToJPEG(au32:array of uint32; w,h:integer; fileName:string);var    writer: TFPCustomImageWriter;  image : TFPMemoryImage; begin  image:=au32ToImage(au32, w,h);   writer:=TFPWriterJPEG.Create;  image.SaveToFile(fileName, writer);   image.free;  writer.free;end;  /////begin  w:=1024; h:=w;  SetLength(au32, w*h);   randomize;  for i:=0 to w*h-1 do    au32[i]:=random($ff000000);   au32ToJPEG(au32, w,h, 'au32.jpg');end. ---------------------------------------------------------------------- Zvoni · 2022-01-28 10:14 i take it, your array of UInt32 contains the Color-Values? The only thing coming to mind: you would have to find the property of TImage which actually contains the color-information per x/y-coordinate (a TCanvas, TBitmap, whatever?). That's assuming that Property is a 2D-Array representing height and width with the value being the color IIRC, the memory-layout of a 2D-Array is "column"-wise, meaning: e.g. Let's say you have 8 x 4 2D-Array (8 rows and 4 columns), so your array of UInt32 would have 32 Members [0..31] "cell" [0,1] (First Row, second column) would have a memory-address of cell[7,0] (8th Row, 1st column) + 4 bytes Addr.   Cell 1000   0,0 1004   1,0 1008   2,0 1012   3,0 1016   4,0 1020   5,0 1024   6,0 1028   7,0 1032   0,1 1036   1,1 1040   2,1 1044   3,1 In that case: Bring your array of UInt32 in the "correct" order and then copy it over to [0,0] Note: I have no idea how SetPixel works (as in: Is it just assigning the Value to x,y or is there some additional black magic happening) Though, might be completely wrong here ---------------------------------------------------------------------- rforcen · 2022-01-28 10:34 yes the array contains 8 bit ARGB values coded in uint32, i was looking for something more direct in the line of facilities provided by image magick or pillow in python, anyhow the coded added to my initial post can do the trick by now, thankx ---------------------------------------------------------------------- wp · 2022-01-28 11:07 In the attachment there is a solution based on TRawImage and TBitmap.LoadFromRawImage; it does not require a temporary image file. ---------------------------------------------------------------------- rforcen · 2022-01-28 11:14 Wow!, thankx that's exactly what i was looking for!  using it, coded a mandelbrot fractal browser with MT generation https://github.com/rforcen/fpc/tree/main/mandelbrot edit: changed generation engine to c++ and gained a x2 boost, same with: https://github.com/rforcen/fpc/tree/main/voronoi