如何将一个bmp 图片存入一个缓存中,得到缓存的buffer和size(取缓存)? (50分)

  • 主题发起人 LittleDot
  • 开始时间
应该先计算Bmp大小,在申请缓存空间吧
 
The following example opens a file named 'test.txt'
and reads the entire file into a dynamically allocated buffer.
The buffer and the size of the file are then passed to a routine t
hat processes the text, and finally the dynamically allocated buffer is freed
and the file is closed.

var

F: file;
Size: Integer;
Buffer: PChar;
begin
AssignFile(F, 'test.txt');
Reset(F, 1);
try
Size := FileSize(F);
GetMem(Buffer, Size);
try
BlockRead(F, Buffer^, Size);
ProcessFile(Buffer, Size);
finally
FreeMem(Buffer);
end;
finally
CloseFile(F);
end;

end;
 
procedure TGraphic.LoadFromFile(const Filename: string);
var
Stream: TStream;
Size:LongInt;
begin
Stream := TFileStream.Create(Filename, fmOpenRead or fmShareDenyWrite);
try
LoadFromStream(Stream);
Size:=Stream.Size;
finally
Stream.Free;
end;
end;
 
接受答案了.
 
顶部