我是新手,所以请不要对我太苛刻。这个概念非常简单,我希望我的用户查看我网站的某个部分,在他们的机器上截取屏幕截图并上传回我的网站。
我在网上的课程中没有看到任何明显的错误,但我猜上传部分有问题,因为当我主持课程时,我的帐户中没有截图 img。在本地,下面设置为 C:/ 的路径就像有人帮助我一样工作正常。如何让它在网络上工作?
import java.applet.*;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.*;
import java.io.*;
import javax.imageio.ImageIO;
public class ScreenShot extends Applet {
static boolean captureScreenShot(String uploadPath)
{
boolean isSuccesful = false;
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture;
try {
URL whatismyip = new URL("http://mysite.com/misc.php?page=showremoteaddr");
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
String ip = in.readLine(); //you get the IP as a String
capture = new Robot().createScreenCapture(screenRect);
// screen shot image will be save at given path with name "screen.jpeg"
ImageIO.write(capture, "png", new File( uploadPath, ip + ".png"));
isSuccesful = true;
} catch (AWTException awte) {
awte.printStackTrace();
isSuccesful = false;
}
catch (IOException ioe) {
ioe.printStackTrace();
isSuccesful = false;
}
return isSuccesful;
}
public static void main(String [] args){
String path = "/var/chroot/home/content/srvu/srvr/www";
captureScreenShot(path);
}
}