好友
阅读权限25
听众
最后登录1970-1-1
|
本帖最后由 lizf2019 于 2022-11-25 18:12 编辑
搞了一个能每三分钟截取一次屏幕的服务
代码很简单 就while循环延时三分钟
安装是用cmd安装的:
[C] 纯文本查看 复制代码 %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe G:\静心_修为\GetScreen\bin\Debug\GetScreen.exe
pause
但是点击启动就报错:
[C#] 纯文本查看 复制代码
/* 省略using */
namespace GetScreen
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public string _filePath;
public string _fileName;
public string _suffix; //后缀
public ImageFormat _imageFormat;
// public string _cutSize;
//鼠标截屏
public bool _screenShotFlag;
public bool _mouseDownFlag;
public Point _start, _end;
protected override void OnStart(string[] args)
{
//初始化
_filePath = @"C:\PicLogs\"; //默认保存路径
_imageFormat = ImageFormat.Jpeg; //默认图片格式(JPG)
_suffix = ".jpg";
if (!Directory.Exists(_filePath))
{
Directory.CreateDirectory(_filePath);
}
string time = DateTime.Now.Year.ToString() +
string.Format("{0:D2}", DateTime.Now.Month) +
string.Format("{0:D2}", DateTime.Now.Day) +
string.Format("{0:D2}", DateTime.Now.Hour) +
string.Format("{0:D2}", DateTime.Now.Minute) +
string.Format("{0:D2}", DateTime.Now.Second);
Rectangle rect = new Rectangle();
while (true)
{
rect = Screen.PrimaryScreen.Bounds; //获取主显示屏的边界
_screenShotFlag = true;
Image myImage = new Bitmap(rect.Width, rect.Height);
Graphics myGraphics = Graphics.FromImage(myImage); //创建绘图
myGraphics.CopyFromScreen(new Point(0, 0), new Point(0, 0), rect.Size);
//保存图片
string filePathName = string.Concat(_filePath, @"\", _fileName);
myImage.Save(filePathName, _imageFormat);
MessageBox.Show("截图成功,图片保存至路径:" + _filePath, "提示");
Thread.Sleep(1000);//三分钟 180000
}
}
protected override void OnStop()
{
Application.Exit();
}
}
}
一点启动就会报错1064
求助大佬指点 |
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|