Added python project; fixed spelling of folder
This commit is contained in:
BIN
Java Projects/GrabScreen/bin/GrabScreen.jar
Executable file
BIN
Java Projects/GrabScreen/bin/GrabScreen.jar
Executable file
Binary file not shown.
8
Java Projects/GrabScreen/buildJar.sh
Executable file
8
Java Projects/GrabScreen/buildJar.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
function main() {
|
||||
jar cvfm GrabScreen.jar manifest.txt com/itdominator/grabscreen/*.class com/itdominator/grabscreen/resources
|
||||
chmod +x GrabScreen.jar
|
||||
mv GrabScreen.jar bin/
|
||||
}
|
||||
main;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
Java Projects/GrabScreen/manifest.txt
Normal file
1
Java Projects/GrabScreen/manifest.txt
Normal file
@@ -0,0 +1 @@
|
||||
Main-Class: com.itdominator.grabscreen.GrabScreen
|
86
Java Projects/GrabScreen/src/CaptureWindow.java
Normal file
86
Java Projects/GrabScreen/src/CaptureWindow.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.itdominator.grabscreen;
|
||||
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.*;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.shape.*;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
|
||||
public class CaptureWindow extends Application {
|
||||
// Generics
|
||||
private Stage stage;
|
||||
private static final int shadowSize = 50;
|
||||
|
||||
public void captureWindow() {
|
||||
String[] args = new String[0];
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override public void start(Stage stage) {
|
||||
this.stage = stage;
|
||||
this.stage.initStyle(StageStyle.TRANSPARENT);
|
||||
|
||||
Button bttn = new Button("Snap Pic");
|
||||
StackPane stackPane = new StackPane(bttn);
|
||||
stackPane.getChildren().add(createShadowPane());
|
||||
|
||||
stackPane.setStyle(
|
||||
"-fx-background-color: rgba(0, 0, 0, 0.5);" +
|
||||
"-fx-background-insets: " + shadowSize + ";"
|
||||
);
|
||||
|
||||
Scene scene = new Scene(stackPane, 450, 450);
|
||||
scene.setFill(Color.TRANSPARENT);
|
||||
this.stage.setScene(scene);
|
||||
this.stage.show();
|
||||
}
|
||||
|
||||
private Pane createShadowPane() {
|
||||
Pane shadowPane = new Pane();
|
||||
shadowPane.setStyle(
|
||||
"-fx-background-color: white;" +
|
||||
"-fx-effect: dropshadow(gaussian, red, " + shadowSize + ", 0, 0, 0);" +
|
||||
"-fx-background-insets: " + shadowSize + ";"
|
||||
);
|
||||
|
||||
Rectangle innerRect = new Rectangle();
|
||||
Rectangle outerRect = new Rectangle();
|
||||
shadowPane.layoutBoundsProperty().addListener(
|
||||
(observable, oldBounds, newBounds) -> {
|
||||
innerRect.relocate(
|
||||
newBounds.getMinX() + shadowSize,
|
||||
newBounds.getMinY() + shadowSize
|
||||
);
|
||||
innerRect.setWidth(newBounds.getWidth() - shadowSize * 2);
|
||||
innerRect.setHeight(newBounds.getHeight() - shadowSize * 2);
|
||||
|
||||
outerRect.setWidth(newBounds.getWidth());
|
||||
outerRect.setHeight(newBounds.getHeight());
|
||||
|
||||
Shape clip = Shape.subtract(outerRect, innerRect);
|
||||
shadowPane.setClip(clip);
|
||||
});
|
||||
|
||||
return shadowPane;
|
||||
}
|
||||
|
||||
public double getWidth() {
|
||||
return stage.getWidth();
|
||||
}
|
||||
|
||||
public double getHeight() {
|
||||
return stage.getHeight();
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return stage.getX();
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return stage.getY();
|
||||
}
|
||||
}
|
51
Java Projects/GrabScreen/src/GrabScreen.java
Normal file
51
Java Projects/GrabScreen/src/GrabScreen.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.itdominator.grabscreen;
|
||||
|
||||
|
||||
public class GrabScreen extends ProcessScreen {
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (args.length < 1) {
|
||||
helpTxt();
|
||||
return;
|
||||
}
|
||||
|
||||
setCaptureRobot();
|
||||
setSelectedScreenToCapture(0);
|
||||
setScreenCaptureSizeToMax();
|
||||
|
||||
switch (args[0]) {
|
||||
case "base64": captureToBase64();
|
||||
break;
|
||||
case "bufferImg": captureToBuffer();
|
||||
break;
|
||||
case "capArea": captureFromWindow();
|
||||
break;
|
||||
case "testSpeed": testCaptureSpeed();
|
||||
break;
|
||||
default: helpTxt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void helpTxt() {
|
||||
System.out.println("[ Help ]\n" +
|
||||
"Command: java -jar GrabScreen <argument>\n" +
|
||||
"Arguments:\n" +
|
||||
" base64\n" +
|
||||
" bufferImg\n" +
|
||||
" capArea\n" +
|
||||
" testSpeed [Takes 32 screenshots and determins the capture speed.]\n"
|
||||
);
|
||||
}
|
||||
|
||||
private static void testCaptureSpeed() {
|
||||
int count = 1;
|
||||
long beforeTime = System.currentTimeMillis();
|
||||
while ( count < 32 ) {
|
||||
captureToBuffer();
|
||||
count++;
|
||||
}
|
||||
double time = System.currentTimeMillis() - beforeTime;
|
||||
System.out.println( "Seconds it took for 32 screen captures: " + time / 1000 );
|
||||
}
|
||||
}
|
77
Java Projects/GrabScreen/src/ProcessScreen.java
Normal file
77
Java Projects/GrabScreen/src/ProcessScreen.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package com.itdominator.grabscreen;
|
||||
|
||||
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.AWTException;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.util.Base64;
|
||||
|
||||
|
||||
class ProcessScreen {
|
||||
// Classes
|
||||
private static CaptureWindow capWin = new CaptureWindow();
|
||||
|
||||
// Generics
|
||||
private static Rectangle screen;
|
||||
private static Robot robot;
|
||||
private static GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
private static GraphicsDevice[] screens = ge.getScreenDevices();
|
||||
private static ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
private static boolean useCaptureWindow = false;
|
||||
private static String base64Encoded = "";
|
||||
private static int selectedScreen = 0;
|
||||
|
||||
|
||||
public static void setCaptureRobot() {
|
||||
try { robot = new Robot(); } catch (AWTException ex) {}
|
||||
}
|
||||
|
||||
public static void setScreenCaptureSizeToMax() {
|
||||
screen = screens[selectedScreen].getDefaultConfiguration().getBounds();
|
||||
}
|
||||
|
||||
public static void setSelectedScreenToCapture(int selected) {
|
||||
if (selected >= 0 && selected < screens.length) {
|
||||
selectedScreen = selected;
|
||||
} else {
|
||||
System.out.println("Selected screen doesn't exist...");
|
||||
}
|
||||
}
|
||||
|
||||
public static int getScreenDeviceCount() { return screens.length; }
|
||||
|
||||
|
||||
protected static String captureToBase64() {
|
||||
try {
|
||||
ImageIO.write(robot.createScreenCapture(screen), "jpg", baos);
|
||||
baos.flush();
|
||||
base64Encoded = new String(Base64.getEncoder()
|
||||
.encode(baos.toByteArray()));
|
||||
baos.close();
|
||||
} catch (IOException e) { e.getMessage(); }
|
||||
|
||||
System.out.println(base64Encoded);
|
||||
return base64Encoded;
|
||||
}
|
||||
|
||||
protected static BufferedImage captureToBuffer() {
|
||||
return robot.createScreenCapture(screen);
|
||||
}
|
||||
|
||||
protected static void captureFromWindow() {
|
||||
capWin.captureWindow();
|
||||
double w = capWin.getWidth();
|
||||
double h = capWin.getHeight();
|
||||
double x = capWin.getX();
|
||||
double y = capWin.getY();
|
||||
|
||||
}
|
||||
}
|
8
Java Projects/GrabScreen/src/unix_compile.sh
Executable file
8
Java Projects/GrabScreen/src/unix_compile.sh
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
# -Xlint:unchecked
|
||||
function main() {
|
||||
javac *.java
|
||||
rm ../com/itdominator/grabscreen/*.class
|
||||
mv *.class ../com/itdominator/grabscreen/
|
||||
}
|
||||
main;
|
Reference in New Issue
Block a user