rendered paste bodytype
PRGBData = ^TRGBData;
TRGBData = record
R: byte;
G: byte;
B: byte;
end;
PRGBDataArray = ^TRGBDataArray;
TRGBDataArray = array[0..MaxInt shr 3] of TRGBData;
var
xBmp: TBitmap;
iWidth: integer;
iHeight: integer;
iBpp: integer;
pData: PRGBData;
pRow: PRGBData;
iRow: integer;
iRowOffset: integer;
pDest: PChar;
pSource: PChar;
procedure BGR24ToRGB24(Source, Dest: PChar; PixelCount: integer);
begin
while PixelCount > 0 do begin
PChar(Dest)[0] := PChar(Source)[2];
PChar(Dest)[1] := PChar(Source)[1];
PChar(Dest)[2] := PChar(Source)[0];
Dest := Pointer(Integer(Dest) + 3);
Source := Pointer(Integer(Source) + 3);
Dec(pixelCount);
end;
end;
begin
xBmp := TBitmap.Create;
xBmp.LoadFromFile('c:\blah256x256.bmp');
iWidth := xBmp.Width;
iHeight := xBmp.Height;
iBpp := SizeOf(TRGBData); // 3
GetMem(pData, iWidth * iHeight * iBpp);
pDest := @PChar(pData)[(iWidth * iBpp * iHeight) - 1];
pSource := xBmp.ScanLine[0];
iRowOffset := Integer(xBmp.ScanLine[1]) - Integer(pSource);
for iRow := 0 to xBmp.Height - 1 do begin
BGR24ToRGB24(pSource, pDest, iWidth);
Dec(pDest, iWidth * iBpp);
Inc(pSource, iRowOffset);
end;
FreeAndNil(xBmp);
FreeMem(pData);