I have an array of 11 white TBitmaps (32-bit 512x512 pixles = 1 MB) and I want to assign them to TPngImage array to reduce memory usage, I expect the 1 mb white bitmap to become 1.76 KB png and the memory usage drop dramatically I monitored that with task manager and the difference is just 0.824 MB why is that? and what is the best/fast way to lossless compress TBitmaps in memory?
for I := 0 to 10 do
begin
Bitmaps[I] := TBitmap.Create;
Bitmaps[I].PixelFormat := pf32bit;
Bitmaps[I].Canvas.Pen.Color := clWhite;
Bitmaps[I].SetSize(512,512);
Bitmaps[I].Canvas.Rectangle(0,0,512,512);
end;
for I := 0 to 10 do
begin
Pngs[I] := TPngImage.Create;
Pngs[I].Assign(Bitmaps[I]);
Bitmaps[I].Free;
end;
Update
Form @bummi research I think the best thing to do is to save the pngs in a memory stream array, that makes the difference 9.7 MB.
for I := 0 to 10 do
begin
Png := TPngImage.Create;
Png.Assign(Bitmaps[I]);
Streams[I] := TMemoryStream.Create;
Png.SaveToStream(Streams[I]);
Bitmaps[I].Free;
Png.Free;
end;