procedure SaveBitmap32AsTGAFile(bmp32: TBitmap32; TGAFileName:
String);
var
fs: TFileStream;
tgaHeader : TTGAFileHeader;
DataArray:
Array of DWORD;
DataSize, n: DWORD;
begin
ZeroMemory(@tgaHeader, sizeof(tgaHeader));
tgaHeader.imagetype := 2;
tgaHeader.width := bmp32.Width;
tgaHeader.height := bmp32.Height;
tgaHeader.pixeldepth := $20;
// 32 Bit
tgaHeader.descriptor := $08;
// Bits 00001000 = 8 = $08
DataSize := bmp32.Width * bmp32.Height;
SetLength(DataArray, DataSize - 1);
ZeroMemory(@DataArray, sizeof(DataArray));
// Swap Bitmap top / bottom
// >>--> AV / Berechsüberprüfung
for n := bmp32.Width * bmp32.Height-1
downto 0
do
DataArray[n] := bmp32.bits^[n];
// <--<<
fs := TFilestream.Create(TGAFileName, fmCreate);
try
fs.Seek(soFromBeginning, 0);
fs.
Write(tgaHeader, SizeOf(tgaHeader));
fs.
Write(DataArray[0], DataSize);
finally
FreeAndNil(fs);
end;
SetLength(DataArray, 0);
end;