修改截图调用方式,加入可选的尺寸参数

This commit is contained in:
2025-03-22 10:19:54 +08:00
parent d8b3c87347
commit b5fcc72f63
5 changed files with 103 additions and 10 deletions

View File

@@ -28,7 +28,9 @@ type RdpClient struct {
sec *sec.Client // 安全层
pdu *pdu.Client // PDU协议层
channels *plugin.Channels
channels *plugin.Channels
screenWidth int
screenHeight int
}
type Position struct {
@@ -49,13 +51,17 @@ var (
positionMap = make(map[Position]*common.Bitmap)
)
func Newclient(host string, logLevel glog.LEVEL) *RdpClient {
func Newclient(host string, logLevel glog.LEVEL, screenWidth, screenHeight int) *RdpClient {
_logger := log.New(os.Stdout, "", 0)
glog.SetLogger(_logger)
glog.SetLevel(logLevel)
return &RdpClient{Host: host}
return &RdpClient{
Host: host,
screenWidth: screenWidth,
screenHeight: screenHeight,
}
}
func (client *RdpClient) Login(domain, username, password string) ([]byte, error) {
@@ -130,7 +136,7 @@ func (client *RdpClient) initProtocolStack(conn net.Conn, domain, username, pass
// 配置桌面信息
client.channels = plugin.NewChannels(client.sec)
client.mcs.SetClientDesktop(uint16(800), uint16(600))
client.mcs.SetClientDesktop(uint16(client.screenWidth), uint16(client.screenHeight))
// 设置认证信息
client.sec.SetDomain(domain)
@@ -214,7 +220,7 @@ func (client *RdpClient) setEventHandler() {
去除requestedProtocol中的PROTOCOL_HYBRID避免使用NLA
*/
func RealGetScreen(host string) ([]byte, error) {
client := Newclient(host, glog.INFO)
func RealGetScreen(host string, screenWidth, screenHeight int) ([]byte, error) {
client := Newclient(host, glog.INFO, screenWidth, screenHeight)
return client.Login("", "", "")
}

View File

@@ -13,7 +13,7 @@ func TestGetScreen(t *testing.T) {
Windows 10
*/
imgBytes, err := RealGetScreen("127.0.0.1:3389")
imgBytes, err := RealGetScreen("127.0.0.1:3389", 1024, 800)
if err != nil {
t.Fatal(err)
}