栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

获取特定应用程序的屏幕截图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

获取特定应用程序的屏幕截图

以下是一些入门代码:

public void CaptureApplication(string procName){    var proc = Process.GetProcessesByName(procName)[0];    var rect = new User32.Rect();    User32.GetWindowRect(proc.MainWindowHandle, ref rect);    int width = rect.right - rect.left;    int height = rect.bottom - rect.top;    var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);    Graphics graphics = Graphics.FromImage(bmp);    graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy);    bmp.Save("c:\tmp\test.png", ImageFormat.Png);}private class User32{    [StructLayout(LayoutKind.Sequential)]    public struct Rect    {        public int left;        public int top;        public int right;        public int bottom;    }    [Dllimport("user32.dll")]    public static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect);}

可以,但是需要改进:

  • 您可能希望使用其他机制来获取进程句柄(或至少进行一些防御性编码)
  • 如果您的目标窗口不在前景中,您将得到截屏,该屏幕截图的大小/位置正确,但是将被前景中的所有内容填充(您可能希望先将给定的窗口拉入前景中) )
  • 除了将bmp保存到临时目录外,您可能还想做其他事情


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/381538.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号