简体   繁体   English

如何在 windows 通用应用程序中截取特定部分的屏幕截图(与计算机分辨率无关)

[英]How can take an screenshot for an specific section in a windows universal app (doesn't matter the computer resolution)

I'm working in a company where the owner wish take a screenshot of a windows mail app;我在一家公司工作,业主希望截取 windows 邮件应用程序的屏幕截图; specifically the section where the e-mail are show;特别是显示电子邮件的部分; and if the window or the section have an scroll, then must avoid it and take the screenshot of that whole section.如果 window 或该部分有滚动,则必须避开它并截取整个部分的屏幕截图。

I'm building it on a .net console app, and I have download a lot of examples where shows just how to take a screeshot of an specific or any window.我在 .net 控制台应用程序上构建它,我下载了很多示例,其中显示了如何拍摄特定或任何 window 的截图。

The closest code (I think) that I found was this:我发现的最接近的代码(我认为)是这样的:

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;

What customer expects it's to take an screenshot of a windows mail app but as I said before, the section that shows the e-mail in fact.客户期望它截取 windows 邮件应用程序的屏幕截图,但正如我之前所说,实际上显示电子邮件的部分。 So, it must looks something like:所以,它必须看起来像:

Result结果

I am not sure how to do it from a Console Application, as that is very limited, but you can create a screen capture program from Windows Forms significantly easier.我不确定如何从控制台应用程序执行此操作,因为它非常有限,但是您可以从 Windows Forms 创建屏幕捕获程序,这要容易得多。 The course I took from Huw Collingbourne who will teach you how to do it.我从 Huw Collingbourne 那里学习的课程,他会教你如何做。 It is not a small program to type out in this box though.不过,在这个框中输入并不是一个小程序。

The program he teaches had a mainform, then would pop up a smaller transparent form that you would maneuver over the area you want to capture.他教授的程序有一个主窗体,然后会弹出一个较小的透明窗体,您可以在要捕获的区域上进行操作。 To capture you would press the button which would capture the transparent form with this code:要捕获您将按下将使用此代码捕获透明表单的按钮:

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

Going back to the main form the program would put the picture on the picturebox for you to view.回到主窗体,程序会将图片放在图片框上供您查看。

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();
    }

Here are the links to his course https://bitwisecourses.com/p/program-a-screen-capture-tool-in-c-sharp and his course sold through udemy https://www.udemy.com/course/program-a-screen-capture-tool-in-c/learn/lecture/15760316#content以下是他的课程https://bitwisecourses.com/p/program-a-screen-capture-tool-in-c-sharp的链接,他的课程通过 udemy https://www.udemy.com/course/ 出售程序-a-screen-capture-tool-in-c/learn/lecture/15760316#content

bitwisecourses.com is his direct website I believe. bitwisecourses.com 我相信是他的直接网站。 Otherwise Udemy will offer nice discounts like $10-$13 for their various classes.否则,Udemy 将为他们的各种课程提供不错的折扣,例如 10 美元至 13 美元。 Once you bought a bunch and don't do anything for a few months they will try to charge you full price, but you only need to email them and they will start discounting you again.一旦你买了一堆并且几个月不做任何事情,他们会尝试向你收取全价,但你只需要 email 他们就会再次开始给你打折。

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

I hope this helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通用Windows库(UWP)采取截图的方式? - Universal Windows Library (UWP) Way to take screenshot? Windows通用应用程序共享库代码在平台特定项目的XAML中未正确引用 - Windows Universal App Shared Library Code doesn't get referenced properly in XAML of platform specific projects C# - Windows Universal app - 图像源不起作用 - C# - Windows Universal app - Image Source doesn't work Xamarin形式:Windows 10 Universal App防止屏幕截图 - Xamarin forms: Windows 10 Universal App prevent screenshot 无法在通用Windows App中引用所有文件夹 - Can't reference all folders in universal Windows App 无法在Windows 10通用应用程序中接收推送通知 - can't receive push notification in windows 10 universal app 如何以编程方式在Windows手机上截取屏幕截图? - How to programmatically take a screenshot on windows phone? 如何使用透明的Windows WPF截屏 - How to take screenshot with transparent windows WPF 如何在Windows 10通用APP中设置相机分辨率纵横比16; 9 - How to set a Camera Resolution Aspect Ratio 16;9 in Windows 10 Universal APP Chrome无法在命令行中截取屏幕截图 - Can't take screenshot in command line with Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM