下面給你介紹將全屏幕截圖保存到指定目錄下的代碼,希望能對你有幫助:
創新互聯是創新、創意、研發型一體的綜合型網站建設公司,自成立以來公司不斷探索創新,始終堅持為客戶提供滿意周到的服務,在本地打下了良好的口碑,在過去的十載時間我們累計服務了上千家以及全國政企客戶,如發電機維修等企業單位,完善的項目管理流程,嚴格把控項目進度與質量監控加上過硬的技術實力獲得客戶的一致稱揚。
核心代碼為:snapShot方法中的相關邏輯
package Jietu;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class CameraTest {
private String filePreStr; // 默認前綴(選擇存儲路徑例如: D:\\)
private String defName = "cameraImg"; // 默認截圖名稱
static int serialNum = 0; //截圖名稱后面的數字累加
private String imageFormat; // 圖像文件的格式
private String defaultImageFormat = "png"; //截圖后綴
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); //獲取全屏幕的寬高尺寸等數據
public CameraTest() {
filePreStr = defName;
imageFormat = defaultImageFormat;
}
public CameraTest(String s, String format) {
filePreStr = s;
imageFormat = format;
}
public void snapShot() {
try {
// *** 核心代碼 *** 拷貝屏幕到一個BufferedImage對象screenshot
BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle(0, 0, (int) d.getWidth(), (int) d.getHeight()));
serialNum++;
// 根據文件前綴變量和文件格式變量,自動生成文件名
String name = filePreStr + String.valueOf(serialNum) + "." + imageFormat;
File f = new File(name);
System.out.print("Save File " + name);
// 將screenshot對象寫入圖像文件
ImageIO.write(screenshot, imageFormat, f);
System.out.print("..Finished!\n");
} catch (Exception ex) {
System.out.println(ex);
}
}
// 運行之后,即可將全屏幕截圖保存到指定的目錄下面br // 配合前端頁面上面的選擇尺寸等邏輯,傳到后臺,即可實現自由選擇截圖區域和大小的截圖br
public static void main(String[] args) {
CameraTest cam = new CameraTest("d:\\Hello", "png");//
cam.snapShot();
}
}
主要是利用java的幾個先有的函數,如Robot這個類的一個方法createScreenCapture一個獲得一個任意大小的屏幕圖像(在這里是全屏圖像),而所謂的截圖就是在這個圖像上畫出一個矩形,再利用上面的方法獲得這部分的圖像,程序中的cf.setAlwaysOnTop(true)是必需的;看起來是在屏幕上截圖,其實只是在一個在一個內鑲有桌面背景的JFrame中截圖。不知道還有沒有其他的好方法~
附上代碼:
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.*;
public class Camera {
/**
* @param args
*/
public static void main(String[] args) {
CameraJFrame cf=new CameraJFrame();
cf.setAlwaysOnTop(true);
cf.setUndecorated(true);
cf.setVisible(true);
}
}
class CameraJFrame extends JFrame
{
/**
*
*/
private static final long serialVersionUID = 1L;
Dimension di=Toolkit.getDefaultToolkit().getScreenSize();
public CameraJFrame()
{
setSize(di);
getContentPane().add(new CameraJPanel());
}
class CameraJPanel extends JPanel implements MouseListener,MouseMotionListener
{
/**
* flag主要是用來判別狀態。
* 文件的格式名是unname+數字編號,格式是png
*/
private static final long serialVersionUID = 1L;
BufferedImage bi,get;
int startx,starty,endx,endy;
int flag=1;
String filename="unname";
String fileformat="png";
int count=1;
public CameraJPanel()
{
try
{
Robot ro=new Robot();
bi=ro.createScreenCapture(new Rectangle(0,0,di.width,di.height));
}
catch(Exception e)
{
e.printStackTrace();
}
addMouseListener(this);
addMouseMotionListener(this);
}
public void paintComponent(Graphics g)
{
g.drawImage(bi,0,0,di.width,di.height,this);
g.setColor(Color.red);
g.drawRect(startx, starty, endx-startx, endy-starty);
}
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getButton()==MouseEvent.BUTTON3)
{
System.exit(0);
}
else if(e.getClickCount()==2)
{
try
{
Robot ro=new Robot();
get=ro.createScreenCapture(new Rectangle(startx,starty,endx-startx,endy-starty));
String name=filename+String.valueOf(count++)+"."+fileformat;
File f=new File(name);
ImageIO.write(get, fileformat, f);
}
catch(Exception ex)
{
ex.printStackTrace();
}
flag=1; //置flag為1,以便重新開始截圖。
startx=starty=endx=endy=0;
repaint();
}
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
if(flag==1)
{
startx=e.getX();
starty=e.getY();
}
}
public void mouseReleased(MouseEvent e) {
flag=0;
}
public void mouseDragged(MouseEvent e) {
flag=1;
endx=e.getX();
endy=e.getY();
repaint();
}
public void mouseMoved(MouseEvent e) {}
}
}
哎~要是你給我個分就好了!我前幾天剛剛做的!你拿去吧!
/*
作者:泡沫
地址:
功能:用于截取圖片,方便快捷!
mail:yuhuidog#163.com (注意:其中#為@)
*/
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class AWTpicture extends Frame implements MouseListener,MouseMotionListener,ActionListener{
private int firstX,firstY,frameWidth,frameHeight;
private int firstWith,firstHeight,firstPointx,firstPointy;
private BufferedImage bi,sbi,original;
private Robot robot;
private Rectangle rectangle;
private Rectangle rectangleCursor,rectangleCursorUp,rectangleCursorDown,rectangleCursorLeft,rectangleCursorRight;
private Rectangle rectangleCursorRU,rectangleCursorRD,rectangleCursorLU,rectangleCursorLD;
private Image bis;
private Dimension dimension;
private Button button,button2,clearButton;
private Point[] point=new Point[3];
private int width,height;
private int nPoints=5;
private Panel panel;
private boolean drawHasFinish=false,change=false;
private int changeFirstPointX,changeFirstPointY,changeWidth,changeHeight;
private boolean changeUP=false,changeDOWN=false,changeLEFT=false,changeRIGHT=false,changeRU=false,changeRD=false,changeLU=false,changeLD=false;
private boolean clearPicture=false,redraw=false;
private FileDialog fileDialog;
private AWTpicture(){
//取得屏幕大小
dimension=Toolkit.getDefaultToolkit().getScreenSize();
frameWidth=dimension.width;
frameHeight=dimension.height;
fileDialog=new FileDialog(this,"泡沫截圖",FileDialog.SAVE);
rectangle=new Rectangle(frameWidth,frameHeight);
panel=new Panel();
button=new Button("退出");
button.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
button.setBackground(Color.green);
button2=new Button("截取");
button2.setBackground(Color.darkGray);
button2.addActionListener(new MyTakePicture(this));
button2.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
button.addActionListener(this);
clearButton=new Button("重繪");
clearButton.setBackground(Color.green);
clearButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
clearButton.addActionListener(new MyClearPicture(this));
panel.setLayout(new BorderLayout());
panel.add(clearButton, BorderLayout.SOUTH);
panel.add(button, BorderLayout.NORTH);
panel.add(button2, BorderLayout.CENTER);
try {
robot=new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
//截取全屏
bi=robot.createScreenCapture(rectangle);
original=bi;
this.setSize(frameWidth,frameHeight);
this.setUndecorated(true);
this.addMouseListener(this);
this.addMouseMotionListener(this);
this.add(panel,BorderLayout.EAST);
this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
this.setVisible(true);
this.repaint();
}
public static void main(String[] args){
new AWTpicture();
}
public void paint(Graphics g) {
this.drawR(g);
}
//緩存圖片
public void update(Graphics g){
if(bis==null){
bis=this.createImage(frameWidth, frameHeight);
}
Graphics ga=bis.getGraphics();
Color c=ga.getColor();
ga.setColor(Color.black);
ga.fillRect(0, 0, frameWidth, frameHeight);
ga.setColor(c);
paint(ga);
g.drawImage(bis, 0, 0, frameWidth, frameHeight, null);
}
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
public void mouseReleased(MouseEvent e) {
if(!drawHasFinish){
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[1].x;
firstPointy=point[1].y;
}
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[2].x;
firstPointy=point[1].y;
}
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[1].x;
firstPointy=point[2].y;
}
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[2].x;
firstPointy=point[2].y;
}
changeFirstPointX=firstPointx;
changeFirstPointY=firstPointy;
if(point[1]!=null point[2]!=null ){
rectangleCursorUp=new Rectangle(firstPointx+20,firstPointy-10,width-40,20);
rectangleCursorDown=new Rectangle(firstPointx+20,firstPointy+height-10,width-40,20);
rectangleCursorLeft=new Rectangle(firstPointx-10,firstPointy+10,20,height-20);
rectangleCursorRight=new Rectangle(firstPointx+width-10,firstPointy+10,20,height-20);
rectangleCursorLU=new Rectangle(firstPointx-10,firstPointy-10,30,20);
rectangleCursorLD=new Rectangle(firstPointx-10,firstPointy+height-10,30,20);
rectangleCursorRU=new Rectangle(firstPointx+width-10,firstPointy-10,20,20);
rectangleCursorRD=new Rectangle(firstPointx+width-10,firstPointy+height-10,20,20);
drawHasFinish=true;
}
}
//確定每邊能改變大小的矩形
if(drawHasFinish){
rectangleCursorUp=new Rectangle(changeFirstPointX+20,changeFirstPointY-10,changeWidth-40,20);
rectangleCursorDown=new Rectangle(changeFirstPointX+20,changeFirstPointY+changeHeight-10,changeWidth-40,20);
rectangleCursorLeft=new Rectangle(changeFirstPointX-10,changeFirstPointY+10,20,changeHeight-20);
rectangleCursorRight=new Rectangle(changeFirstPointX+changeWidth-10,changeFirstPointY+10,20,changeHeight-20);
rectangleCursorLU=new Rectangle(changeFirstPointX-2,changeFirstPointY-2,10,10);
rectangleCursorLD=new Rectangle(changeFirstPointX-2,changeFirstPointY+changeHeight-2,10,10);
rectangleCursorRU=new Rectangle(changeFirstPointX+changeWidth-2,changeFirstPointY-2,10,10);
rectangleCursorRD=new Rectangle(changeFirstPointX+changeWidth-2,changeFirstPointY+changeHeight-2,10,10);
}
}
public void mouseDragged(MouseEvent e) {
point[2]=e.getPoint();
//if(!drawHasFinish){
this.repaint();
// }
//托動鼠標移動大小
if(change){
if(changeUP){
changeHeight=changeHeight+changeFirstPointY-e.getPoint().y;
changeFirstPointY=e.getPoint().y;
}
if(changeDOWN){
changeHeight=e.getPoint().y-changeFirstPointY;
}
if(changeLEFT){
changeWidth=changeWidth+changeFirstPointX-e.getPoint().x;
changeFirstPointX=e.getPoint().x;
}
if(changeRIGHT){
changeWidth=e.getPoint().x-changeFirstPointX;
}
if(changeLU){
changeWidth=changeWidth+changeFirstPointX-e.getPoint().x;
changeHeight=changeHeight+changeFirstPointY-e.getPoint().y;
changeFirstPointX=e.getPoint().x;
changeFirstPointY=e.getPoint().y;
}
if(changeLD){
changeWidth=changeWidth+changeFirstPointX-e.getPoint().x;
changeHeight=e.getPoint().y-changeFirstPointY;
changeFirstPointX=e.getPoint().x;
}
if(changeRU){
changeWidth=e.getPoint().x-changeFirstPointX;
changeHeight=changeHeight+changeFirstPointY-e.getPoint().y;
changeFirstPointY=e.getPoint().y;
}
if(changeRD){
changeWidth=e.getPoint().x-changeFirstPointX;
changeHeight=e.getPoint().y-changeFirstPointY;
}
this.repaint();
}
}
public void mouseMoved(MouseEvent e) {
point[1]=e.getPoint();
//改變鼠標的形狀
if(rectangleCursorUp!=null rectangleCursorUp.contains(point[1])){
this.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));
change=true;
changeUP=true;
}else if(rectangleCursorDown!=null rectangleCursorDown.contains(point[1])){
this.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
change=true;
changeDOWN=true;
}else if(rectangleCursorLeft!=null rectangleCursorLeft.contains(point[1])){
this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
change=true;
changeLEFT=true;
}else if(rectangleCursorRight!=null rectangleCursorRight.contains(point[1]) ){
this.setCursor(new Cursor(Cursor.W_RESIZE_CURSOR));
change=true;
changeRIGHT=true;
}else if(rectangleCursorLU !=null rectangleCursorLU.contains(point[1])){
this.setCursor(new Cursor(Cursor.NW_RESIZE_CURSOR));
change=true;
changeLU=true;
}else if(rectangleCursorLD !=null rectangleCursorLD.contains(point[1])){
this.setCursor(new Cursor(Cursor.SW_RESIZE_CURSOR));
change=true;
changeLD=true;
}else if(rectangleCursorRU!=null rectangleCursorRU.contains(point[1])){
this.setCursor(new Cursor(Cursor.NE_RESIZE_CURSOR));
change=true;
changeRU=true;
}else if(rectangleCursorRD!=null rectangleCursorRD.contains(point[1])){
this.setCursor(new Cursor(Cursor.SE_RESIZE_CURSOR));
change=true;
changeRD=true;
}else{
this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
changeUP=false;changeDOWN=false;changeRIGHT=false;changeLEFT=false;changeRU=false;
changeRD=false;changeLU=false;changeLD=false;
}
redraw=false;
}
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
class MyTakePicture implements ActionListener{
AWTpicture aWTpicture;
MyTakePicture(AWTpicture aWTpicture){
this.aWTpicture=aWTpicture;
}
//保存圖片
public void actionPerformed(ActionEvent e) {
fileDialog.setVisible(true);
if(changeWidth0){
sbi=bi.getSubimage(changeFirstPointX,changeFirstPointY,changeWidth,changeHeight);
File file=new File(fileDialog.getDirectory());
file.mkdir();
try {
ImageIO.write(sbi, "jpeg",new File(file,fileDialog.getFile()+".jpg") );
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
class MyClearPicture implements ActionListener{
AWTpicture aWTpicture;
MyClearPicture(AWTpicture aWTpicture){
this.aWTpicture=aWTpicture;
}
public void actionPerformed(ActionEvent e) {
drawHasFinish=false;
change=false;
redraw=true;
rectangleCursorUp=null;
rectangleCursorDown=null;
rectangleCursorLeft=null;
rectangleCursorRight=null;
rectangleCursorRU=null;
rectangleCursorRD=null;
rectangleCursorLU=null;
rectangleCursorLD=null;
changeWidth=0;
changeHeight=0;
aWTpicture.repaint();
}
}
public void drawR(Graphics g){
g.drawImage(bi, 0,0,frameWidth,frameHeight, null);
if(point[1]!=null point[2]!=null !drawHasFinish !redraw){
int[] xPoints={point[1].x,point[2].x,point[2].x,point[1].x,point[1].x};
int[] yPoints={point[1].y,point[1].y,point[2].y,point[2].y,point[1].y};
width=(point[2].x-point[1].x)0?(point[2].x-point[1].x):(point[1].x-point[2].x);
height=(point[2].y-point[1].y)0?(point[2].y-point[1].y):(point[1].y-point[2].y);
changeWidth=width;
changeHeight=height;
Color c=g.getColor();
g.setColor(Color.red);
g.drawString(width+"*"+height, point[1].x, point[1].y-5);
//畫點
/*int i;
if()*/
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[1].x;
firstPointy=point[1].y;
}
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[2].x;
firstPointy=point[1].y;
}
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[1].x;
firstPointy=point[2].y;
}
if(point[1].xpoint[2].x point[1].ypoint[2].y){
firstPointx=point[2].x;
firstPointy=point[2].y;
}
g.fillRect(firstPointx-2,firstPointy-2 , 5,5);
g.fillRect(firstPointx+(width)/2,firstPointy-2 , 5,5);
g.fillRect(firstPointx+width-2,firstPointy-2 , 5,5);
g.fillRect(firstPointx+width-2,firstPointy+ height/2-2, 5,5);
g.fillRect(firstPointx+width-2,firstPointy+height-2, 5,5);
g.fillRect(firstPointx+(width)/2,firstPointy+height-2, 5,5);
g.fillRect(firstPointx-2,firstPointy+height-2, 5,5);
g.fillRect(firstPointx-2,firstPointy+ height/2-2, 5,5);
//畫矩形
//g.drawString("fafda", point[1].x-100, point[1].y-5);
g.drawPolyline(xPoints, yPoints, nPoints);
}
if(change){
g.setColor(Color.red);
g.drawString(changeWidth+"*"+changeHeight, changeFirstPointX, changeFirstPointY-5);
g.fillRect(changeFirstPointX-2,changeFirstPointY-2 , 5,5);
g.fillRect(changeFirstPointX+(changeWidth)/2,changeFirstPointY-2 , 5,5);
g.fillRect(changeFirstPointX+changeWidth-2,changeFirstPointY-2 , 5,5);
g.fillRect(changeFirstPointX+changeWidth-2,changeFirstPointY+ changeHeight/2-2, 5,5);
g.fillRect(changeFirstPointX+changeWidth-2,changeFirstPointY+changeHeight-2, 5,5);
g.fillRect(changeFirstPointX+(changeWidth)/2,changeFirstPointY+changeHeight-2, 5,5);
g.fillRect(changeFirstPointX-2,changeFirstPointY+changeHeight-2, 5,5);
g.fillRect(changeFirstPointX-2,changeFirstPointY+ changeHeight/2-2, 5,5);
g.drawRect(changeFirstPointX, changeFirstPointY, changeWidth, changeHeight);
}
}
}
事實上,如果您想以Java實現網頁截圖,也就是“輸入一段網址,幾秒鐘過后就能截取一張網頁縮略圖”的效果。那么,您至少有3種方式可以選擇。
1、最直接的方式——使用Robot
方法詳解:該方法利用Robat提供的強大桌面操作能力,硬性調用瀏覽器打開指定網頁,并將網頁信息保存到本地。
優勢:簡單易用,不需要任何第三方插件。
缺點:不能同時處理大量數據,技術含量過低,屬于應急型技巧。
實現方法:使用如下代碼即可。
[java] view plaincopy
public static void main(String[] args) throws MalformedURLException,
IOException, URISyntaxException, AWTException {
//此方法僅適用于JdK1.6及以上版本
Desktop.getDesktop().browse(
new URL("").toURI());
Robot robot = new Robot();
robot.delay(10000);
Dimension d = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
int width = (int) d.getWidth();
int height = (int) d.getHeight();
//最大化瀏覽器
robot.keyRelease(KeyEvent.VK_F11);
robot.delay(2000);
Image image = robot.createScreenCapture(new Rectangle(0, 0, width,
height));
BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = bi.createGraphics();
g.drawImage(image, 0, 0, width, height, null);
//保存圖片
ImageIO.write(bi, "jpg", new File("google.jpg"));
}
2、最常規的方式——利用JNI,調用第三方C/C++組件
方法詳解:目前來講,Java領域對于網頁截圖組件的開發明顯不足(商機?),當您需要完成此種操作時,算得上碰到了Java的軟肋。但是,眾所周知Java也擁有強大的JNI能力,可以輕易將C/C++開發的同類組件引為己用。不懂可以扣五七八零二四一四四
優勢:實現簡單,只需要封裝對應的DLL文件,就可以讓Java實現同類功能。
劣勢:同其他JNI實現一樣,在跨平臺時存在隱患,而且您的程序將不再屬于純Java應用。
實現方法:可參見此用例,具體封裝何種C/C++組件請自行選擇。
PS:示例來源于ACA HTML to Image Converter項目( ),這是一個收費的HTML轉Image第三方組件,但封裝方式在Java中大同小異。
引用JNI封裝:
[java] view plaincopy
import sun.awt.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.peer.*;
public class Snap
{
static
{
System.loadLibrary("Snap");
}
public static void main( String[] argv )
{
Snap t_xSnap = new Snap();
t_xSnap.Start("", "snapshot-google.png");
}
public native void Start(String pi_strURL, String pi_strImageName);
}
CPP部分的實現:
[java] view plaincopy
#include windows.h
#include atlbase.h
#include "snap.h"
#pragma comment(lib,"atl.lib")
#import "./../../acawebthumb.dll" no_namespace
JNIEXPORT void JNICALL Java_Snap_Start(JNIEnv *pEnv, jobject, jstring pi_strUrl, jstring pi_strFileName)
{
CoInitialize(0);
_bstr_t t_strUrl = pEnv-GetStringUTFChars(pi_strUrl, 0);
_bstr_t t_strFileName = pEnv-GetStringUTFChars(pi_strFileName, 0);
IThumbMakerPtr HTML_Converter = NULL;
HRESULT hr = HTML_Converter.CreateInstance(L"ACAWebThumb.ThumbMaker");
if (SUCCEEDED(hr))
{
HTML_Converter-SetURL(t_strUrl);
if ( 0 == HTML_Converter-StartSnap() )
HTML_Converter-SaveImage(t_strFileName);
}
if (HTML_Converter)
HTML_Converter.Release();
CoUninitialize();
}
以該組件圖像化yahoo界面的效果圖:
3、最扎實的方法——自行解析HTML標記,并將其圖像化
方法詳解:眾所周知,HTML之所以在瀏覽器中以具體的網頁格式出現,并非服務器端傳了一整個應用到客戶端,而是源自于瀏覽器對于客戶端自行解析的結果。因此,只要我們將對應的解析一一實現,那么將網頁圖形化,就將不是什么難事。
優勢:純Java實現,一勞永逸,一旦開發完成則永遠通用,而且有一定的商用價值。
劣勢:開發費時,且需要針對不同語法做精確分析,才能保證輸出的基本正確。尤其在涉及到JavaScript解析時,難度將尤其增大。
實現方法:目前尚無具體案例可供參考。但是,由于Java有jdic之類的瀏覽器項目存在(),而Java圖形界面又屬繪制生成。從理論上說,我們可以將所有具備Graphics的組件圖形化保存。
而如果自行解析,那么您需要建立HTML解析器(或使用第三方的,萬幸Java在這方面的組件很多),了解Java2D機制,了解何時該使用drawString繪制文字,何時又該使用drawImage插入圖片等等。
謝謝采納!
本文題目:java截圖軟件代碼 java實現網頁截圖
地址分享:http://m.newbst.com/article22/dogpcjc.html
成都網站建設公司_創新互聯,為您提供云服務器、品牌網站設計、網頁設計公司、做網站、微信公眾號、響應式網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯