1
我要問的一部分截圖,如果有辦法(applet或任何想象還有)採取在網頁中DIV內容的截圖???小程序渣取我的網頁
,我發現這個Java代碼,以全屏幕截圖:
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 javax.imageio.ImageIO;
public class ScreenShot
{
/**
method to capture screen shot
@param String uploadPath to save screen shot as image
@returns boolean true if capture successful else false
*/
boolean captureScreenShot(String uploadPath)
{
boolean isSuccesful = false;
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture;
try
{
capture = new Robot().createScreenCapture(screenRect);
// screen shot image will be save at given path with name "screen.jpeg"
ImageIO.write(capture, "jpg", new File(uploadPath, "screen.jpeg"));
isSuccesful = true;
}
catch (AWTException awte)
{
awte.printStackTrace();
isSuccesful = false;
}
catch (IOException ioe)
{
ioe.printStackTrace();
isSuccesful = false;
}
return isSuccesful;
}
}
感謝
服用內容的截圖上一個div在網頁中 - 你能詳細說明一下嗎? –
是的,我有apenlayers的地圖對象,我需要採取截圖只爲地圖,而不是完整的頁面 –