i've searched and searched and can't seem to find anything that describes what i'm look to do in delphi code. the solutins are sometimes close but not close enough for me to figure out. so here i am asking..
i have many bitmaps that i am retreaving from screenshots. what i have been doing is saving to bitmaps_001.bmp, but it takes a lot a storage space, so i upgraded the routine to save as bitmaps_001.png, and this saves even greater space, but now i want to save to one file, a tfilestream, and read from it using a tprogressbar that i can drag left/right as the images show on screen.
basically, i am trying to acomplish the following:
procedure SaveBMPtoStream(st: tfilestream; bmp: tbitmap);
procedure ReadBMPfrStream(st: tfilestream; bmp: tbitmap; bnum: integer);
so far the code (below)works as is, (it writes and reads in one bitmap image at the press of a tbutton) but i can only write one bitmap image. i need to write as many images as necessary per session to the tfilestream in realtime, possibly using a ttimer control and let it write as many images until i press the stop tbutton. what can i do to modify the code below to solve this? thank you.
i am running windows xp, attached to external usb3.0 1tb drive with NTFS file system.
type
TMS = TFileStream;
var
MS: TMS;
pos: int64; // bnum for 0-99,999 images.
sz: integer; // size of the image/stream ?
//write bitmaps to stream
procedure SaveBMPtoStream(ms: TMS; Bmp: TBitmap; bnum: integer);
begin
// create (or append to) stream
if fileexists('d:\streams\s.stm') then MS := TFileStream.Create('d:\streams\s.stm', fmOpenReadWrite)
else MS := TFileStream.Create('d:\streams\s.stm', fmCreate);
//sz:=MS.Size; pos:=ms.Position;
bmp.SaveToStream(MS);
// free stream
ms.free;
end;
//read bitmaps from stream
procedure ReadBMPfrStream(ms: TMS; Bmp: TBitmap; bnum: integer);
begin
// open stream.
MS := TFileStream.Create ('d:\streams\s.stm', fmOpenReadWrite);
// read in bitmap from stream
//sz:=MS.Size; pos:=ms.Position;
bmp.LoadFromStream(MS);
// free stream
ms.free;
end;
like type TMS: TFileStream;
. ;) If the information does not have to persist accross sessions, you can probably keep a separate index of bitmap number - stream position/size and copy that part to a temporary stream for reading. Otherwise, you can read bitmap info headers from the stream to advance the stream until the requested index and then copy again, or build an index the same way at the start of the application. But the latter would be more work. – Barracuda