顺便给你一个龌鹾的方法:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
ProgressBar1: TProgressBar;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
const
bufsize = 2048;
var
bmpStream,tmpStream:TMemoryStream;
bmpLength,LeftSize:LongInt;
buf:array [0..bufsize-1] of char;
Max:Integer;
begin
bmpStream :=TMemoryStream.Create;
tmpStream :=TMemoryStream.Create;
bmpStream.LoadFromFile('d:/backup/xxxx.bmp'); //读取源文件
bmpLength :=bmpStream.Size;
if bmpLength < bufsize
then LeftSize :=bufsize
else LeftSize :=bmpLength;
bmpStream.Position :=0;
tmpStream.Position :=0;
ProgressBar1.Position :=0;
ProgressBar1.Max :=600;
Max :=ProgressBar1.Max;
while LeftSize > 0 do //模拟显示进度
begin
if LeftSize>bufsize
then begin
bmpStream.ReadBuffer(buf,bufsize);
tmpStream.WriteBuffer(buf,bufsize);
ProgressBar1.Position :=Trunc(ProgressBar1.Position + (bufsize / bmpLength)* Max);
end
else begin
bmpStream.ReadBuffer(buf,LeftSize);
tmpStream.WriteBuffer(buf,LeftSize);
ProgressBar1.Position :=Trunc(ProgressBar1.Position + (LeftSize / bmpLength)* Max);
end;
LeftSize :=LeftSize - bufsize;
end ;
ProgressBar1.Position :=ProgressBar1.Max;
tmpStream.Position :=0;
Image1.Picture.Bitmap.LoadFromStream(tmpStream);
bmpStream.Free;
tmpStream.Free;
end;
end.