unit BMPLaden;
interface
uses Windows, Classes, SysUtils, GR32, Graphics;
procedure BitmapLaden(Datei: TFileName; Bitmap: TBitmap);
overload;
procedure BitmapLaden(Datei: TFileName; Bitmap: TBitmap32);
overload;
implementation
function BitmapVerify(FileName: TFileName): TMemoryStream;
var
fh: TBitmapFileHeader;
ih: TBitmapInfoHeader;
Offset: DWORD;
Buffer: Pointer;
begin
result := TMemoryStream.Create;
result.LoadFromFile(FileName);
try
result.Position:=0;
result.ReadBuffer(fh, SizeOf(fh));
result.ReadBuffer(ih, SizeOf(ih));
Offset:=fh.bfOffBits-(SizeOf(TBitmapFileHeader)+SizeOf(TBitmapInfoHeader));
if Offset>0
then begin
GetMem(Buffer, ih.biSizeImage);
try
result.Position:=fh.bfOffBits;
result.ReadBuffer(Buffer^, ih.biSizeImage);
fh.bfSize:=fh.bfSize-Offset;
fh.bfOffBits:=fh.bfOffBits-Offset;
result.Position:=0;
result.WriteBuffer(fh, SizeOf(fh));
result.Position:=fh.bfOffBits;
result.WriteBuffer(Buffer^, ih.biSizeImage);
result.Size:=fh.bfSize;
finally
FreeMem(Buffer, ih.biSizeImage);
end;
end;
finally
result.Position := 0;
//<---hatte ich vergessen^^
end;
end;
procedure BitmapLaden(Datei: TFileName; Bitmap: TBitmap);
var
BitmStream: TMemoryStream;
begin
BitmStream := BitmapVerify(Datei);
Bitmap.LoadFromStream(BitmStream);
FreeAndNil(BitmStream);
end;
procedure BitmapLaden(Datei: TFileName; Bitmap: TBitmap32);
var
BitmStream: TMemoryStream;
begin
BitmStream := BitmapVerify(Datei);
Bitmap.LoadFromStream(BitmStream);
FreeAndNil(BitmStream);
end;
end.