相关疑难解决方法(0)

如何解决使用c#在Windows服务上捕获屏幕截图的问题?

首先,我需要感谢Mr."eddie_cat",以便就我的问题提供有效的答复.他拥有"ScreenCapture"方法的功劳.虽然这种方法不能解决我的问题(在Windows服务端它不起作用),但我相信代码可以在普通的Windows窗体中用于屏幕捕获.

以为我无法找到解决问题的解决方案,我从"Davide Piras"先生那里找到了一个很好的建议.Windows服务无法在Windows 7中获取屏幕截图

他的帖子说:

"Windows服务的设计也是在没有用户连接的情况下运行,它的工作方式就像服务器进程总是向上和聆听,或者正在做某事或者空闲.

我认为你需要的是一个客户端应用程序,它在每个登录用户的会话中运行,并最终完成工作,然后,如果需要,与服务进行通信以完成一些工作.

我在这里说,不是让Windows服务在0以外的其他会话中运行,而是可以创建一个小的可执行文件(可能根本没有UI),从每个用户登录的所有用户的启动文件夹启动.这样的应用程序然后在正确的会话内运行并且可以访问它,它可以获取屏幕截图,然后将其存储在自己的某个地方或在Windows服务中调用一些端点(始终在会话0中运行)并使服务详细说明屏幕截图取自它的客户端应用程序.

这就是我这样做的方式,而不是尝试一些"神奇"来告诉Vista和7在用户会话中启动服务,最终在系统启动时还没有登录."

.net c# screen-capture winforms

1
推荐指数
1
解决办法
1064
查看次数

用户活动记录、遥测(以及全局异常处理程序中的变量)

背景:

我正在处理一个非常旧的应用程序,它很少并且非常间歇性地生成异常。

目前的做法:

通常我们程序员使用全局异常处理程序处理罕见的未知数,连接如下:

[STAThread]
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
private static void Main()
{
    Application.ThreadException += new ThreadExceptionEventHandler(UIThreadException);
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); 
    AppDomain.CurrentDomain.UnhandledException +=
        new UnhandledExceptionEventHandler(UnhandledException);

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new OldAppWithLotsOfWierdExceptionsThatUsersAlwaysIgnore());
}

private static void UIThreadException(object sender, ThreadExceptionEventArgs t)
{
    //-------------------------------
    ReportToDevelopers("All the steps & variables you need to repro the problem are: " + 
    ShowMeStepsToReproduceAndDiagnoseProblem(t));
    //-------------------------------

    MessageToUser.Show("It’s not you, it’s us. This is our fault.\r\n Detailed information about this error has automatically been recorded and we have been notified.Yes, we do look at …
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net debugging exception

1
推荐指数
1
解决办法
4744
查看次数

为什么这段代码将截图保存为bmp而不是gif,为什么不保存整个区域?

我将计时器刻度事件设置为250毫秒:

private void timer4_Tick(object sender, EventArgs e)
{
    if (pictureboximagestosavecount == 72)
    {
        timer4.Enabled = false;
    }
    else
    {
        Bitmap bmp = new Bitmap(this.Width, this.Height);
        Rectangle rect = new Rectangle(this.Location.X, this.Location.Y, this.Width, this.Height);
        pictureboximagestosavecount++;
        savePictureBox(pictureBox1, @"c:\temp\pboximages\" + pictureboximagestosavecount.ToString("D6") + "pbimg.gif");
        this.DrawToBitmap(bmp, rect);
        bmp.Save(@"c:\temp\pboximages\" + pictureboximagestosavecount.ToString("D6") + "form.gif");
    }
}
Run Code Online (Sandbox Code Playgroud)

首先,我使用savePictureBox方法将pictureBox保存为gif.其次我保存form1:

bmp.Save(@"c:\temp\pboximages\" + pictureboximagestosavecount.ToString("D6") + "form.gif");
Run Code Online (Sandbox Code Playgroud)

在timer4停止后,我有一个基本点击事件,我从保存的文件中创建动画gif:

private void animatedgifbutton_Click(object sender, EventArgs e)
{
    DirectoryInfo di1;
    FileInfo[] fi1;
    di1 = new DirectoryInfo(@"c:\temp\pboximages\");
    fi1 = di1.GetFiles("*form.gif");
    List<string> newImages = new List<string>();
    for …
Run Code Online (Sandbox Code Playgroud)

.net c# winforms

0
推荐指数
1
解决办法
192
查看次数

为什么我的应用程序告诉我我的剪贴板显示为空时显然不是?

我试图用控制台应用程序截取我的屏幕截图,然后将其保存到我的桌面但由于某种原因..它告诉我,我的剪贴板是空的时候显然它不是..如果你检查代码你可以看到我按PrintScreen,当您这样做时,它会将其保存到剪贴板.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace ScreenshotConsole
{
    class Program
    {

        static void Main(string[] args)
        {
            screenshot();
            Console.WriteLine("Printescreened");
            saveScreenshot();
            Console.ReadLine();
        }


        static void screenshot()
        {
            SendKeys.SendWait("{PRTSC}");
        }

        static void saveScreenshot()
        {
            //string path;
            //path = "%AppData%\\Sys32.png"; // collection of paths
            //path = Environment.ExpandEnvironmentVariables(path);

            if (Clipboard.ContainsImage() == true)
            {
                Image image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
                image.Save("image.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            else
            {
                Console.WriteLine("Clipboard empty.");
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# clipboard screenshot console-application

0
推荐指数
1
解决办法
158
查看次数