Files
VisualSapfor/src/_VisualDVM/Passes/All/MakeScreenShot.java
2024-10-14 12:14:01 +03:00

38 lines
1.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package _VisualDVM.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.Passes.Project.CurrentProjectPass;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.file.Paths;
public class MakeScreenShot extends CurrentProjectPass {
File outputfile = null;
@Override
public String getIconPath() {
return "/icons/ScreenShot.png";
}
//http://www.nookery.ru/pishem-programmy-dly-sozdaniy-sreenshot/
@Override
protected void body() throws Exception {
DisplayMode display = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
int x = display.getWidth();
int y = display.getHeight();
BufferedImage bufferedImage = new Robot().createScreenCapture(new Rectangle(x, y));
//-
String res_name = Utils_.getDateName("screenshot") + ".png";
outputfile = Paths.get(target.getAttachmentsDirectory().getAbsolutePath(), res_name).toFile();
//-
ImageIO.write(bufferedImage, "png", outputfile);
}
@Override
protected void showDone() throws Exception {
// UI.Info("Скриншот для текушего проекта сохранён во вложениях\nпод именем " + outputfile.getName());
if (Desktop.isDesktopSupported()) {
// Desktop.getDesktop().open(outputfile.getParentFile());
Desktop.getDesktop().open(outputfile);
}
}
}