package camera;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class pro extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("撮る");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
pic sub=new pic();
sub.makedata("ren.jpg");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 50, 50);
primaryStage.setTitle("Camera");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
package camera;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.AWTException;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.*;
public class pic {
void makedata(String file){
Rectangle screenSize = new Rectangle(0, 0, 2560, 1000);
try {
Robot robot = new Robot();
ImageIO.write(robot.createScreenCapture(screenSize), "jpg", new File(file));
}catch (AWTException e2) {e2.printStackTrace();}
catch (IOException e) {e.printStackTrace(); }
}
}
最終更新:2016年03月02日 20:15