我的代码如下:每一张图片都是999×715的,在进行读盘时,由于不是多线程,
当图片比较多时,一般我这里是10张之后,总会有一点停顿。
麻烦您告知应该如何实现多线程读文件。
我尝试创建了一个线程,但是没有效果,还是有停顿。请指教通过多线程应该如何实现。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
Timer1: TTimer;
Image1: TImage;
procedure Timer1Timer(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
n:integer;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
image1.Top:=image1.Top-1;
//panel1.Top:=panel1.Top-1;
if (image1.top mod 50)=0 then
begin
inc
;
image1.Picture.LoadFromFile('e:/ppt_'+inttostr((n mod 70)+1)+'.bmp');
//image1.Top:=176;
end;
if image1.Top<0 then image1.Top:=800;
//application.ProcessMessages;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
n:=0;
image1.Picture.LoadFromFile('e:/ppt_1.bmp');
timer1.Enabled:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
doublebuffered:=true;
end;
end.
窗体文件
object Form1: TForm1
Left = -4
Top = -4
Width = 1032
Height = 770
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Image1: TImage
Left = 7
Top = 704
Width = 1034
Height = 721
end
object BitBtn1: TBitBtn
Left = 16
Top = 80
Width = 105
Height = 41
Caption = 'BitBtn1'
TabOrder = 0
OnClick = BitBtn1Click
end
object Timer1: TTimer
Enabled = False
Interval = 50
OnTimer = Timer1Timer
Left = 144
Top = 96
end
end