如何在Windows Universal应用程序中为特定部分拍摄屏幕截图(与计算机分辨率无关)

问题描述 投票:0回答:1

我在一家公司中工作,业主希望对Windows Mail应用程序进行截图;特别是显示电子邮件的部分;并且如果窗口或分区具有滚动条,则必须避免滚动并获取整个分区的屏幕截图。

我正在.net控制台应用程序上构建它,并且我下载了很多示例,其中仅显示如何对特定或任何窗口进行快照。

我发现的最接近的代码是(我认为)是这样:

IntPtr current = IntPtr.Zero;
        IntPtr handle = IntPtr.Zero;

        List<IntPtr> thumbs = new List<IntPtr>();
        if (handle == IntPtr.Zero)
            handle = ((System.Windows.Interop.HwndSource)System.Windows.Interop.HwndSource.FromVisual(this)).Handle;

        current = DWM.GetWindow(handle, DWM.GetWindowCmd.First);

        do
        {
            int GWL_STYLE = -16;
            int TASKSTYLE = 0x10000000 | 0x00800000;
            if (TASKSTYLE == (TASKSTYLE & DWM.GetWindowLong(current, GWL_STYLE)))
            {
                thumbs.Add(current);
            }

            current = DWM.GetWindow(current, DWM.GetWindowCmd.Next);

            if (current == handle)
                current = DWM.GetWindow(current, DWM.GetWindowCmd.Next);
        }
        while (current != IntPtr.Zero);

        this.DataContext = thumbs;

客户期望它将截取Windows Mail应用程序的屏幕快照,但是正如我之前所说,实际上显示电子邮件的部分。因此,它必须类似于:

Result

c# .net decompiler
1个回答
0
投票

我不确定如何从控制台应用程序执行此操作,这是非常有限的,但是您可以从Windows Forms创建屏幕捕获程序非常容易。我从Huw Collingbourne修读的课程将教你如何做。不过,在此框中输入内容不是一个小程序。

他教的程序有一个主窗体,然后会弹出一个较小的透明窗体,您可以在要捕获的区域上进行操作。要捕获您将按下按钮,它将使用以下代码捕获透明表单:

formRect = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);
this.Hide();
mainForm.GrabRect(formRect);

返回主程序,程序会将图片放在图片框中供您查看。

public void GrabRect(Rectangle rect)
    {
        int rectWidth = rect.Width - rect.Left;
        int rectHeight = rect.Height - rect.Top;
        Bitmap bm = new Bitmap(rectWidth, rectHeight);
        Graphics g = Graphics.FromImage(bm);
        g.CopyFromScreen(rect.Left, rect.Top, 0, 0, new Size(rectWidth, rectHeight));
        this.pb_screengrab.Image = bm;
        Clipboard.SetImage(bm);
        g.Dispose();
    }

以下是他课程的链接https://bitwisecourses.com/p/program-a-screen-capture-tool-in-c-sharp他的课程通过udemy出售https://www.udemy.com/course/program-a-screen-capture-tool-in-c/learn/lecture/15760316#content

bitwisecourses.com是我相信的直接网站。否则,Udemy将为他们的各个班级提供不错的折扣,如$ 10- $ 13。一旦您购买了一堆并且几个月不做任何事情,他们会尝试向您收取全价,但您只需向他们发送电子邮件,他们就会再次打折给您。

我把我所做的一切都放在这里:https://github.com/johnbnstx/HuwBurn_ScreenGrab

我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.