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