I need to load the data of bitmap files into a buffer in the RGBA format, but i'm somewhat lost.

Reading the wiki and the source i got to the following code:

procedure DumpMem(Data: PCardinal; Size: Integer);
var
 i: Integer;
 Color: TRGBA;
begin
 for i := 0 to Size - 1 do
 begin
   Color := TRGBA(Data[i]);
   WriteLn('Red: ', Color.R, ' Green: ', Color.G,
     ' Blue: ',Color.B, ' Alpha: ', Color.A);
 end;
end;

var
 ImgReader: TLazReaderBMP;
 IntfImg: TLazIntfImage;
begin
 ImgReader := TLazReaderBMP.Create;
 IntfImg := TLazIntfImage.Create(0,0);
 IntfImg.DataDescription.Init_BPP32_B8G8R8A8_M1_BIO_TTB(0, 0);
 IntfImg.LoadFromFile('red.bmp', ImgReader);

DumpMem(PCardinal(IntfImg.PixelData), IntfImg.DataDescription.Height * IntfImg.DataDescription.Width);

 ImgReader.Destroy;
 IntfImg.Destroy;
end;

red.bmp is a 2x2 bmp file filled with red. (attached)

the DumpMem leads to different results if the program is run in IDE or outside it (Probably PixelData is not pointing to the data).

What's wrong with this code? Should i pass the width, height when init datadescription?

Luiz




<<inline: red.bmp>>

Reply via email to