Skip to content

Commit

Permalink
updated ti fix the save/load of an empty TBitmap like already done in…
Browse files Browse the repository at this point in the history
… Olf.FMX.Streams.pas unit
  • Loading branch information
DeveloppeurPascal committed Mar 5, 2024
1 parent 487332b commit 5b0a265
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions Olf.VCL.Streams.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ procedure SaveBitmapToStream(ABitmap: TBitmap; AToStream: TStream);
if not assigned(AToStream) then
raise exception.create('Need an existing stream to save the bitmap !');

ms := TMemoryStream.create;
try
ABitmap.SaveToStream(ms);
size := ms.size;
if not assigned(ABitmap) then
begin
size := 0;
AToStream.WriteData(size);
if (size > 0) then
begin
ms.Position := 0;
AToStream.CopyFrom(ms, size);
end
else
begin
ms := TMemoryStream.create;
try
ABitmap.SaveToStream(ms);
size := ms.size;
AToStream.WriteData(size);
if (size > 0) then
begin
ms.Position := 0;
AToStream.CopyFrom(ms, size);
end;
finally
ms.free;
end;
finally
ms.free;
end;
end;

Expand All @@ -43,20 +51,22 @@ function LoadBitmapFromStream(AFromStream: TStream): TBitmap;
if not assigned(AFromStream) then
raise exception.create('Need an existing stream to load the bitmap !');

ms := TMemoryStream.create;
try
if (AFromStream.ReadData(size) <> sizeof(size)) then
result := nil
else
begin
if (AFromStream.ReadData(size) <> sizeof(size)) then
result := nil
else if (size < 1) then
result := nil
else
begin
ms := TMemoryStream.create;
try
ms.CopyFrom(AFromStream, size);
ms.Position := 0;
result := TBitmap.create;
result.LoadFromStream(ms);
finally
ms.free;
end;
finally
ms.free;
end;
end;

end.
end.

0 comments on commit 5b0a265

Please sign in to comment.