For j := 0 To Bmp.HeigHt - 1 Do
Begin
P := MainImage.Bitmap.Scanline[j];
Q := Bmp.Scanline[j];
For i := 0 To Bmp.Width - 1 Do
Begin
Q[i] := P[i];
End;
End;这段代码如何用两个线程处理我是这样写的
在主线程里
Tstruct = Record
pic:TBitmap;
src:TZoomImage;
p, q:PByteArray;
End;Procedure threadpicsca(Var pb:pstruct); Stdcall;
Var
i, j :Integer;
Begin
If WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 Then Begin
// CS.Enter; For j := 0 To pb.pic.Height - 1 Do
Begin
pb.p := pb.src.Bitmap.Scanline[j];
pb.q := pb.pic.Scanline[j];
For i := 0 To pb.pic.Width - 1 Do
Begin pb.Q[i] := pb.q[i];
End;
ReleaseMutex(hMutex); End;
// CS.Leave;
End; // ReleaseSemaphore(hSemaphore, 1, nil);
End;Procedure threadpicsca1(Var pb:pstruct); Stdcall;
Var
i, j :Integer;
Begin
If WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 Then Begin
// CS.Enter;
Begin For j := pb.pic.Height Div 2 + 1 To pb.pic.Height - 1 Do
Begin
pb.p := pb.src.Bitmap.Scanline[j];
pb.q := pb.pic.Scanline[j];
For i := 0 To pb.pic.Width - 1 Do
Begin pb.Q[i] := pb.q[i];
End;
ReleaseMutex(hMutex); End;
// CS.Leave;
End; End;
End;
struct := GetMemory(SizeOf(Tstruct));
ZeroMemory(struct, SizeOf(Tstruct));
pstruct = ^tstruct;
struct.pic := Bmp;
struct.src := MainImage;
hMutex := CreateMutex(Nil, False, Nil);
H1 := CreateThread(Nil, 0, @threadpicsca, @struct, 0, ID);
H2 := CreateThread(Nil, 0, @threadpicsca1,@struct, 0, ID);老是提示存储空间不足,无法处理此命令
Begin
P := MainImage.Bitmap.Scanline[j];
Q := Bmp.Scanline[j];
For i := 0 To Bmp.Width - 1 Do
Begin
Q[i] := P[i];
End;
End;这段代码如何用两个线程处理我是这样写的
在主线程里
Tstruct = Record
pic:TBitmap;
src:TZoomImage;
p, q:PByteArray;
End;Procedure threadpicsca(Var pb:pstruct); Stdcall;
Var
i, j :Integer;
Begin
If WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 Then Begin
// CS.Enter; For j := 0 To pb.pic.Height - 1 Do
Begin
pb.p := pb.src.Bitmap.Scanline[j];
pb.q := pb.pic.Scanline[j];
For i := 0 To pb.pic.Width - 1 Do
Begin pb.Q[i] := pb.q[i];
End;
ReleaseMutex(hMutex); End;
// CS.Leave;
End; // ReleaseSemaphore(hSemaphore, 1, nil);
End;Procedure threadpicsca1(Var pb:pstruct); Stdcall;
Var
i, j :Integer;
Begin
If WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 Then Begin
// CS.Enter;
Begin For j := pb.pic.Height Div 2 + 1 To pb.pic.Height - 1 Do
Begin
pb.p := pb.src.Bitmap.Scanline[j];
pb.q := pb.pic.Scanline[j];
For i := 0 To pb.pic.Width - 1 Do
Begin pb.Q[i] := pb.q[i];
End;
ReleaseMutex(hMutex); End;
// CS.Leave;
End; End;
End;
struct := GetMemory(SizeOf(Tstruct));
ZeroMemory(struct, SizeOf(Tstruct));
pstruct = ^tstruct;
struct.pic := Bmp;
struct.src := MainImage;
hMutex := CreateMutex(Nil, False, Nil);
H1 := CreateThread(Nil, 0, @threadpicsca, @struct, 0, ID);
H2 := CreateThread(Nil, 0, @threadpicsca1,@struct, 0, ID);老是提示存储空间不足,无法处理此命令
而且分配了空间啊那你说该怎么写啊
其实我最在意的怎么组合两个不同线程里的struct
地址会错乱吧同步的问题啊
Begin
P := MainImage.Bitmap.Scanline[j];
Q := Bmp.Scanline[j];
Move(P[0], Q[0], Bmp.Width);
End;
没必要用线程了。
Q := Bmp.Scanline[0];
Move(P[0], Q[0], Bmp.Width * Bmp.Height);