Leonardo M. Ram? wrote 9 lines
Hi, I'm working with a library that let me get a pointer to an UInt8
array containing the pixels of an image.
To show the image on screen, using Lazarus, I must know the
Red,Green,Blue and Alpha values of each pixel (am I right?), how can I
convert each byte of the UInt8 array to RGBA?
Thanks in advance,
--
Let me answer to myself.
I didn't know that I can use lBuffer as an array, so, the index 0 -> Red, 1 -> Green, 2 -> Blue, 3 -> Alpha.
Here's how a buffer can be paint on a form using TBGRABitmap:
lBmp := TBGRABitmap.Create(FImgWidth, FImgHeight);
try
for y := 0 to lBmp.Height-1 do
begin
p := lBmp.Scanline[y];
for x := 0 to lBmp.Width-1 do
begin
p^.red := lBuffer[0];
p^.green := lBuffer[1];
p^.blue := lBuffer[2];
p^.alpha := lBuffer[3];
inc(p);
inc(lBuffer);
end;
end;
// Self is a TForm
lBmp.Draw(Self.Canvas, 0, 0);
finally
lbmp.Free;
end;