uses
ZLibEx;
procedure CompressBitmap_Slow(bmp: TBitmap;
var Data:
string);
var
ms : TMemoryStream;
buf : pointer;
size : integer;
begin
ms := TMemoryStream.Create;
bmp.SaveToStream(ms);
ZCompress(ms.Memory, ms.Size, buf, size);
SetLength(Data, size);
Move(buf^, Data[1], size);
FreeMem(buf);
ms.Free;
end;
procedure CompressBitmap(bmp: TBitmap;
var Data:
string);
var
cs: TZCompressionStream;
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
cs := TZCompressionStream.Create(ms,zcDefault);
// clDefault ist schneller als clMax
bmp.SaveToStream(cs);
cs.Free;
SetLength(Data, ms.Size);
Move(ms.Memory^, Data[1], ms.Size);
ms.Free;
end;
procedure UnCompressBitmap(
const Data:
string; bmp: TBitmap);
var
ms : TMemoryStream;
buf : pointer;
size : integer;
outsize:integer;
begin
try
size:=0;
outsize:=Length(Data) * 3;
ZDecompress(@Data[1], Length(Data), buf,outsize, size);
except
on E:
Exception do begin
E.
Message := Format('
Error Decompressing Buffer (Len = %d):'#13#10'
%s', [Length(Data), e.
Message]);
raise;
end;
end;
ms := TMemoryStream.Create;
ms.
Write(buf^, outSize);
FreeMem(buf);
ms.Position := 0;
Assert(bmp <>
nil);
bmp.LoadFromStream(ms);
ms.Free;
end;