L
logpie
Unregistered / Unconfirmed
GUEST, unregistred user!
我这有一个186X111的图象,我把他分成6块,没快31*111大
放在6个线程里分别 COPYRECT
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
BitBtn1: TBitBtn;
Memo1: TMemo;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TMythread=class(Tthread)
private
newstr:string;
protected
procedure Execute;override;
procedure ChangeCap;
Public
constructor Create(ns:string);
end;
var
Form1: TForm1;
MyRect:Trect;
Trdlst:TLIST;
CS:TRTLCriticalSection;
implementation
{$R *.dfm}
constructor TMythread.Create(ns:string);
begin
newstr:=ns;
inherited create(false);
end;
procedure Tmythread.Execute ;
var i,j:integer;
str:string;
begin
FreeonTerminate :=true;
EnterCriticalSection(CS);
if newstr= '1' then
begin
with Myrectdo
begin
top:=0;
left:=0;
right:=31;
bottom:=form1.Image1.Height;
end;
end;
if newstr='2' then
begin
with Myrectdo
begin
top:=0;
left:=31;
right:=62;
bottom:=form1.Image1.Height;
end;
end;
if newstr='3'then
begin
with Myrectdo
begin
top:=0;
left:=62;
right:=93;
bottom:=form1.Image1.Height;
end;
end;
if newstr='4' then
begin
with Myrectdo
begin
top:=0;
left:=93;
right:=124;
bottom:=form1.Image1.Height;
end;
end;
if newstr='5' then
begin
with Myrectdo
begin
top:=0;
left:=124;
right:=155;
bottom:=form1.Image1.Height;
end;
end;
if newstr='6' then
begin
with Myrectdo
begin
top:=0;
left:=155;
right:=186;
bottom:=form1.Image1.Height;
end;
end;
synchronize(ChangeCap);
LeaveCriticalSection(CS);
end;
procedure TMythread.ChangeCap ;
begin
form1.image2.Canvas.CopyRect(Myrect,form1.image1.Picture.Bitmap.Canvas,Myrect);---------------------(*)
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var i:integer;
begin
TrdLst:=TList.Create ;
InitializeCriticalsection(CS);
for i:=1 to 6do
TrdLst.Add(TMythread.Create(inttostr(i)));
end;
end.
上面代码运行正常,IMAGE2里分块出现了IMAGE1的图象。
但是如果我不用IMAGE2来COPYRECT,而用一个TBITMAP来COPYRECT,那么这个TBITMAP居然是空的
比如:
var
Form1: TForm1;
MyRect:Trect;
Trdlst:TLIST;
CS:TRTLCriticalSection;
bmp1:Tbitmap;
implementation
...
...
...
if newstr='6' then
begin
with Myrectdo
begin
top:=0;
left:=155;
right:=186;
bottom:=form1.Image1.Height;
end;
end;
bmp1.Canvas.CopyRect(Myrect,form1.image1.Picture.Bitmap.Canvas,Myrect);
bmp1.SaveToFile('f:/a1.bmp');
synchronize(ChangeCap);
LeaveCriticalSection(CS);
end;
...
...
end.
照理说A1。BMP因该是被分成的第6块图象,可实际上A1。BMP什么也没有,0字节大小
这是怎么回事?
放在6个线程里分别 COPYRECT
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
BitBtn1: TBitBtn;
Memo1: TMemo;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TMythread=class(Tthread)
private
newstr:string;
protected
procedure Execute;override;
procedure ChangeCap;
Public
constructor Create(ns:string);
end;
var
Form1: TForm1;
MyRect:Trect;
Trdlst:TLIST;
CS:TRTLCriticalSection;
implementation
{$R *.dfm}
constructor TMythread.Create(ns:string);
begin
newstr:=ns;
inherited create(false);
end;
procedure Tmythread.Execute ;
var i,j:integer;
str:string;
begin
FreeonTerminate :=true;
EnterCriticalSection(CS);
if newstr= '1' then
begin
with Myrectdo
begin
top:=0;
left:=0;
right:=31;
bottom:=form1.Image1.Height;
end;
end;
if newstr='2' then
begin
with Myrectdo
begin
top:=0;
left:=31;
right:=62;
bottom:=form1.Image1.Height;
end;
end;
if newstr='3'then
begin
with Myrectdo
begin
top:=0;
left:=62;
right:=93;
bottom:=form1.Image1.Height;
end;
end;
if newstr='4' then
begin
with Myrectdo
begin
top:=0;
left:=93;
right:=124;
bottom:=form1.Image1.Height;
end;
end;
if newstr='5' then
begin
with Myrectdo
begin
top:=0;
left:=124;
right:=155;
bottom:=form1.Image1.Height;
end;
end;
if newstr='6' then
begin
with Myrectdo
begin
top:=0;
left:=155;
right:=186;
bottom:=form1.Image1.Height;
end;
end;
synchronize(ChangeCap);
LeaveCriticalSection(CS);
end;
procedure TMythread.ChangeCap ;
begin
form1.image2.Canvas.CopyRect(Myrect,form1.image1.Picture.Bitmap.Canvas,Myrect);---------------------(*)
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
var i:integer;
begin
TrdLst:=TList.Create ;
InitializeCriticalsection(CS);
for i:=1 to 6do
TrdLst.Add(TMythread.Create(inttostr(i)));
end;
end.
上面代码运行正常,IMAGE2里分块出现了IMAGE1的图象。
但是如果我不用IMAGE2来COPYRECT,而用一个TBITMAP来COPYRECT,那么这个TBITMAP居然是空的
比如:
var
Form1: TForm1;
MyRect:Trect;
Trdlst:TLIST;
CS:TRTLCriticalSection;
bmp1:Tbitmap;
implementation
...
...
...
if newstr='6' then
begin
with Myrectdo
begin
top:=0;
left:=155;
right:=186;
bottom:=form1.Image1.Height;
end;
end;
bmp1.Canvas.CopyRect(Myrect,form1.image1.Picture.Bitmap.Canvas,Myrect);
bmp1.SaveToFile('f:/a1.bmp');
synchronize(ChangeCap);
LeaveCriticalSection(CS);
end;
...
...
end.
照理说A1。BMP因该是被分成的第6块图象,可实际上A1。BMP什么也没有,0字节大小
这是怎么回事?