📄 tstripmonitorthreadunit.~pas
字号:
unit TStripMonitorThreadUnit;
interface
uses
IdTCPServer,IdGlobal,Classes,windows,Forms,SysUtils,Jpeg,Graphics,Variants,
Types;
type
TStripMonitorThread = class(TThread)
private
ThePriority :integer;
TheImageType :integer;
ThePicPixFmt :integer;
TheImageQos :integer;
TheAThread :TIdPeerThread;
TheNewScrBmp :TBitMap; ////用于捕获当前屏幕的图象
TheOldScrBmp :TBitmap; //缓存上次屏幕的图象,用于比较
TheVarChildBmp :TBitMap; //变化的子区域1..n
TheOldChildBmp :TBitmap; //上次缓存中的变化的子区域1..n
TheScrRect :TRect; //监视区域在屏幕中的矩形坐标
isTheFirst :Boolean; //是第一次运行吗?不是则进行比较传输
TheSendStream :TMemoryStream; //发送块的数据流
Thejpg :TJpegImage; //jpeg格式压缩引擎
protected
procedure GetTargetBmp;
Function isSameTheBmp(TheNewBmp,TheOldBmp:TBitmap):Boolean;
procedure Execute; override;
public
constructor Create(AThread:TIdPeerThread;ThisPriority,
ThisImageType,ThisPicPixFmt,ThisImageQoS:Integer);
destructor Destroy; override;
end;
implementation
constructor TstripMonitorThread.Create(AThread:TIdPeerThread;ThisPriority,
ThisImageType,ThisPicPixFmt,ThisImageQoS:Integer);
begin
inherited Create(true);
FreeOnTerminate:=True;//主动释放,不是自动释放
ThePriority :=ThisPriority; //设置线程的优先级
TheImageType :=ThisImageType; //截屏的图象类型 bmp---jpg
ThePicPixFmt :=ThisPicPixFmt; //转换的像素颜色位 1 2 4 8 16 24 32
TheImageQos :=ThisImageQos; //如果是jpg 格式,则为压缩比
TheAThread :=AThread;
//设置线程的优先级
if ThePriority=1 then Priority:=tpIdle;
if ThePriority=2 then Priority:=tpLowest;
if ThePriority=3 then Priority:=tpLower;
if ThePriority=4 then Priority:=tpNormal;
if ThePriority=5 then Priority:=tpHigher;
if ThePriority=6 then Priority:=tpHighest;
if ThePriority=7 then Priority:=tpTimeCritical;
Try
TheOldScrBmp :=TBitmap.Create; //上次目标屏幕区域
TheNewScrBmp :=TBitMap.Create; //当前目标屏幕区域
TheVarChildBmp :=TBitMap.Create; //变化的子区域1..120
TheOldChildBmp :=TBitmap.Create; //上次缓存中的变化的子区域1..120
Thejpg :=TJpegImage.Create;//jpeg格式压缩引擎
TheSendStream :=TMemoryStream.Create; // 发送块数据流
except
Self.Terminate;
exit;
end;
//屏幕矩形的设置
TheScrRect.Left :=0;
TheScrRect.Right :=Screen.Width;
TheScrRect.Top :=0;
TheScrRect.Bottom:=Screen.Height;
//这为屏幕区域分块传输大小
TheNewScrBmp.Width:=Screen.Width; //用于捕获当前屏幕的图象
TheNewScrBmp.Height:=Screen.Height;
TheOldScrBmp.Width:=Screen.Width; //缓存上次屏幕的图象,用于比较
TheOldScrBmp.Height:=Screen.Height;
TheVarChildBmp.Width:=80; //获取局部的图形块用于传输
TheVarChildBmp.Height:=32;
TheOldChildBmp.Width:=80; //获取局部的图形块用于比较
TheOldChildBmp.Height:=32;
if ThePicPixFmt=1 then TheNewScrBmp.PixelFormat:=pf1bit;
if ThePicPixFmt=2 then TheNewScrBmp.PixelFormat:=pf4bit;
if ThePicPixFmt=3 then TheNewScrBmp.PixelFormat:=pf8bit;
if ThePicPixFmt=4 then TheNewScrBmp.PixelFormat:=pf16bit;
if ThePicPixFmt=5 then TheNewScrBmp.PixelFormat:=pf24bit;
if ThePicPixFmt=6 then TheNewScrBmp.PixelFormat:=pf32bit;
if ThePicPixFmt=7 then TheNewScrBmp.PixelFormat:=pf24bit;
if TheImageType=1 then TheNewScrBmp.PixelFormat:=pf24bit;
TheOldScrBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheVarChildBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheOldChildBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
Suspended :=False;//立即执行
isTheFirst:=True;//是第一次监视屏幕吗?
end;
procedure TStripMonitorThread.GetTargetBmp;
Var
dc : HDC;
iII : LongBool;
begin
Dc:=GetDC(GetDesktopWindow);
if Dc=Null then
begin
TheAThread.Connection.Disconnect;
self.Terminate;
exit;
end;
Repeat
iII:=StretchBlt(TheNewScrBmp.Canvas.Handle, 0,0,TheNewScrBmp.Width,
TheNewScrBmp.Height,dc,0,0,
Screen.Width,Screen.Height,SRCCOPY);
until iII=True;
ReleaseDC(GetDesktopWindow,Dc);
end;
Function TStripMonitorThread.isSameTheBmp(TheNewBmp,TheOldBmp:TBitmap):Boolean;
var
i,j : integer;
OldP24,NewP24 : PInteger; //24位颜色
OldP16,NewP16 : PWordArray;
OldP8,NewP8 : PByteArray;
varCount : integer;
begin
if ThePicPixFmt=1 then//==================1位颜色================1
begin
TheNewBmp.PixelFormat:=pf8bit;
TheOldBmp.PixelFormat:=pf8bit;
varCount:=0;
For i:=0 to TheOldBmp.Height-1 do
begin
OldP8:=TheOldBmp.ScanLine[i];//获取扫描线--old
NewP8:=TheNewBmp.ScanLine[i];//获取扫描线--New
For j:=0 to TheOldBmp.Width-1 do
begin
if OldP8[j]<>NewP8[j] then
VarCount:=VarCount+1;
if VarCount>5 then
begin
Result:=False;
TheNewBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheNewBmp.PixelFormat:=TheNewBmp.PixelFormat;
Exit;
end;
end;
end;
//====================================恢复原来的像素颜色位格式
TheNewBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheNewBmp.PixelFormat:=TheNewBmp.PixelFormat;
Result:=True;
Application.ProcessMessages;//如果不进行传递则休息一会
end;
if ThePicPixFmt=2 then//==================4位颜色================2
begin
TheNewBmp.PixelFormat:=pf8bit;
TheOldBmp.PixelFormat:=pf8bit;
varCount:=0;
For i:=0 to TheOldBmp.Height-1 do
begin
OldP8:=TheOldBmp.ScanLine[i];//获取扫描线--old
NewP8:=TheNewBmp.ScanLine[i];//获取扫描线--New
For j:=0 to TheOldBmp.Width-1 do
begin
if OldP8[j]<>NewP8[j] then
VarCount:=VarCount+1;
if VarCount>5 then
begin
Result:=False;
TheNewBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheNewBmp.PixelFormat:=TheNewBmp.PixelFormat;
Exit;
end;
end;
end;
//====================================恢复原来的像素颜色位格式
TheNewBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheNewBmp.PixelFormat:=TheNewBmp.PixelFormat;
Result:=True;
Application.ProcessMessages;//如果不进行传递则休息一会
end;
if ThePicPixFmt=3 then//==================8位颜色==================3
begin
TheNewBmp.PixelFormat:=pf8bit;
TheOldBmp.PixelFormat:=pf8bit;
varCount:=0;
For i:=0 to TheOldBmp.Height-1 do
begin
OldP8:=TheOldBmp.ScanLine[i];//获取扫描线--old
NewP8:=TheNewBmp.ScanLine[i];//获取扫描线--New
For j:=0 to TheOldBmp.Width-1 do
begin
if OldP8[j]<>NewP8[j] then
VarCount:=VarCount+1;
if VarCount>5 then
begin
Result:=False;
TheNewBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheNewBmp.PixelFormat:=TheNewBmp.PixelFormat;
Exit;
end;
end;
end;
//====================================恢复原来的像素颜色位格式
TheNewBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheNewBmp.PixelFormat:=TheNewBmp.PixelFormat;
Result:=True;
Application.ProcessMessages;//如果不进行传递则休息一会
end;
if ThePicPixFmt=4 then//==================16位颜色=================4
begin
TheNewBmp.PixelFormat:=pf16bit;
TheOldBmp.PixelFormat:=pf16bit;
varCount:=0;
For i:=0 to TheOldBmp.Height-1 do
begin
OldP16:=TheOldBmp.ScanLine[i];//获取扫描线--old
NewP16:=TheNewBmp.ScanLine[i];//获取扫描线--New
For j:=0 to TheOldBmp.Width-1 do
begin
if OldP16[j]<>NewP16[j]then
VarCount:=VarCount+1;
if VarCount>5 then
begin
Result:=False;
TheNewBmp.PixelFormat:=TheNewScrBmp.PixelFormat;
TheNewBmp.PixelFormat:=TheNewBmp.PixelFormat;
Exit;
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -