.net - 如何从 Web 应用程序捕获 .NET 中的屏幕截图?

标签 .net asp.net

在Java中,我们可以这样做:

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;

...

public void captureScreen(String fileName) throws Exception {

   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Rectangle screenRectangle = new Rectangle(screenSize);
   Robot robot = new Robot();
   BufferedImage image = robot.createScreenCapture(screenRectangle);
   ImageIO.write(image, "png", new File(fileName));

}

...

我们如何从 Web 应用程序在 .NET 中执行此操作?从应用程序中捕获客户端的屏幕并将其发送到服务器。

最佳答案

.NET 图形对象有一个名为 CopyFromScreen() 的方法,该方法将捕获屏幕的矩形区域并将其复制到位图。最好的方法类似于以下内容:

public void CaptureImage(Point SourcePoint, Point DestinationPoint, Rectangle Selection, string FilePath)
{
    using (Bitmap bitmap = new Bitmap(Selection.Width, Selection.Height)) {
        using (Graphics g = Graphics.FromImage(bitmap)) {
            g.CopyFromScreen(SourcePoint,DestinationPoint, Selection.Size);
        }
        bitmap.Save(FilePath, ImageFormat.Bmp);
    }
}

关于.net - 如何从 Web 应用程序捕获 .NET 中的屏幕截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2916144/

相关文章:

c# - 使用 EPPlus 合并单元格?

c# - 使用 ASP.NET Webforms 的 Ajax 发布

c# - 如何在新实现的接口(interface)或基类之间做出决定?

c# - 如何使字符串比较在进程/线程级别不区分大小写?

c# - C# 中的右对齐组合框

.net - IIS7/WPAS : Multiple WCF services in same AppDomain?

c# - 通过带有自签名 SSL 证书的邮件服务器从 .net 应用程序发送电子邮件

.Net 与 SSIS : What should SSIS be used for?

c# - asp.net 自定义控件属性依赖于另一个属性

javascript - 如何防止客户端/服务器两侧文本框的sql注入(inject)