import captureScreen.filter.BMPfilter;
import captureScreen.filter.GIFfilter;
import captureScreen.filter.JPGfilter;
import captureScreen.filter.PNGfilter;
import org.apache.commons.lang.StringUtils;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
/**
* * 截图工具
* 2022年12月5日18点48分*
*
* @author hawk*
*/
public class MyScreenshotx {
private JPanel beijing;
private JPanel right, top, left, bottom;// 上下左右面板
private JPanel controlPanel;
private JButton doCopyButton, doSaveButton, closeButton, ctrlZButton;// 截图操作按钮
private JRadioButton mindian, defaultdian, maxdian;// 字体线条粗细单选框
private JRadioButton ashkuang, bluekuang, greenkuang, redkuang, whitekuang, yellowkuang; // 颜色单选框
private JButton boxButton, circleButton, brushButton, textButton;// 形状画图按钮
private ButtonGroup groupsize, groupcolor;// 单选按钮组
private int startX, startY, endX, endY;// 框选移动位置
private int startXTemp, startYTemp, endXTemp, endYTemp;// 临时存储移动位置
private int smoveX, smoveY, emoveX, emoveY;// 移动的位置
private int boxStartX, boxStartY, boxEndX, boxEndY; // 画笔画框的大小
private boolean topMove = false, leftMove = false;
private boolean move = false;
private Dimension screenSize;
private BufferedImage bufImage;
private boolean isShowTip = true;//是否显示提示.如果鼠标左键一按,则提示就不再显示了
private int isShowTipCount = 0;// 显示提示计数
private Point showTipPoint = new Point();
private boolean isbBox = false, isCircle = false, isBrush = false, isText = false, isCtrlZ = false;
private JPanel frameSelection;
private int mouseEvent = 0;
private List<List<Object>> boxArr = new ArrayList<>();// 保存矩形数组
private List<List<Object>> circleArr = new ArrayList<>();// 保存圆形数组
private List<BrushLine> brushArr = new ArrayList<>(); // 保存画笔画形
private List<Map<String, Object>> textArr = new ArrayList<>(); // 保存画笔画形
private List<Point> brush = null; // 当前画笔画形
private List<Object> ctrlZList = new ArrayList<>();
boolean[] clickedMoveStatus = {false, false, false, false};// 按下/移动/抬起/点击
private int[] frameSelectionArea = {0, 0}; // 选择框的面积0w 1h
private String paintbrush = "";
private GridBagLayout gridBagLayout = new GridBagLayout();
private GridBagConstraints gridBagConstraints = new GridBagConstraints();
private JPanel toptext, lefttext, righttext, buttomtext;
private static int width = 800;
private static int height = 500;
public MyScreenshotx(JFrame jFrame) {
addButtonGroup();
// 获取屏幕尺寸
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
width = screenSize.width;
height = screenSize.height;
// 创建需要截取的矩形区域
Rectangle rect = new Rectangle(0, 0, screenSize.width, screenSize.height);
try {
bufImage = new Robot().createScreenCapture(rect);// 截屏操作
} catch (AWTException e) {
e.printStackTrace();
}
beijing.add(createSelectionPanel(jFrame));
boxButton.addActionListener(e -> {
restoreReleasedDragged();
isbBox = true;
paintbrush = "box";
controlPanel.setSize(new Dimension(controlPanel.getWidth(), 80));
ctrlZButton.setEnabled(true);
ctrlZButton.requestFocus(true);
});
circleButton.addActionListener(e -> {
restoreReleasedDragged();
isCircle = true;
paintbrush = "circle";
controlPanel.setSize(new Dimension(controlPanel.getWidth(), 80));
ctrlZButton.setEnabled(true);
ctrlZButton.requestFocus(true);
});
brushButton.addActionListener(e -> {
restoreReleasedDragged();
isBrush = true;
paintbrush = "brush";
controlPanel.setSize(new Dimension(controlPanel.getWidth(), 80));
ctrlZButton.setEnabled(true);
ctrlZButton.requestFocus(true);
});
textButton.addActionListener(e -> {
restoreReleasedDragged();
isText = true;
paintbrush = "text";
controlPanel.setSize(new Dimension(controlPanel.getWidth(), 80));
ctrlZButton.setEnabled(true);
ctrlZButton.requestFocus(true);
});
ctrlZButton.addActionListener(e -> ctrlZClear());
closeButton.addActionListener(e -> jFrame.dispose());
doSaveButton.addActionListener(e -> doSaveBufImage(jFrame));
doCopyButton.addActionListener(e -> doCopyBufImage(jFrame));
}
// 判断画笔状态
public boolean isPaintComponent() {
return isCtrlZ || isText || isBrush || isCircle || isbBox;
}
// 判断画笔状态
public boolean isReleasedDragged() {
return !isbBox && !isCircle && !isBrush && !isText;
}
// 还原画笔状态
public void restoreReleasedDragged() {
isText = false;
isBrush = false;
isCircle = false;
isbBox = false;
}
/**
* 框选选中面板*
*
* @param jFrame
* @return
*/
public JPanel createSelectionPanel(JFrame jFrame) {
// 创建选择帧
frameSelection = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
// System.out.println("正在绘画....paintComponent = " + (clickedMoveStatus[0] && clickedMoveStatus[1] || isPaintComponent()));
if (clickedMoveStatus[0] && clickedMoveStatus[1] || isPaintComponent()) {
g.setColor(Color.green);
for (int i = 0; i < 2; i++) {
g.drawLine(startX, startY - i, endX, startY - i);
g.drawLine(startX, endY - i, endX, endY - i);
g.drawLine(startX + i, startY, startX + i, endY);
g.drawLine(endX - i, startY, endX - i, endY);
}
g.fillRect(startX - 5, startY - 5, 10, 10); // 上线的 起点描点
g.fillRect((startX + endX) / 2 - 5, startY - 5, 10, 10); // 上线的 中间描点
g.fillRect(endX - 5, startY - 5, 10, 10); // 上线的 终点描点
g.fillRect(startX - 5, endY - 5, 10, 10); // 下线的 起点描点
g.fillRect((startX + endX) / 2 - 5, endY - 5, 10, 10); // 下线的 中间描点
g.fillRect(endX - 5, endY - 5, 10, 10); // 下线的 终点描点
g.fillRect(startX - 5, (startY + endY) / 2 - 5, 10, 10); // 右线的 中间描点
g.fillRect(endX - 5, (startY + endY) / 2 - 5, 10, 10); // 左线的 中间描点
boxWrite(g); // 画出存量图形
Integer lineSize;
if (paintbrush.equals("box")) {
// System.out.println("box画笔 boxStartX = " + boxStartX + ", boxStartY = " + boxStartY + ", boxEndX = " + boxEndX + ", boxEndY = " + boxEndY);
g.setColor(Color.decode(groupcolor.getSelection().getA
没有合适的资源?快使用搜索试试~ 我知道了~
Java swing实现框选截图小工具java截图框选仿wx
共94个文件
png:52个
class:24个
xml:9个
需积分: 5 13 下载量 6 浏览量
2022-12-05
18:09:54
上传
评论
收藏 106KB ZIP 举报
温馨提示
想做个Java的局域网相互传东西和聊天,正巧遇到想要截图在网上找来找去没有找到看起来合适的,最想要的还是有点阴影凸显一下截图区域,然后在截图区写字画图形。 思路是这样:1屏幕截图放到背景面板,2在用一个面板盖住它,3在盖住的面板上用Graphics画出框选区域,4在框选的区域在进行图图画画,5然后再把款框选的区域再截图一次保存下来。 因为网上找不到类似的然后我就分享出来,方便有想法的小伙伴不用重复造轮子了。
资源推荐
资源详情
资源评论
收起资源包目录
MyScreenshotx.zip (94个子文件)
MyScreenshotx
pom.xml 1KB
src
MyScreencx.form 20KB
MyScreenshotx.java 41KB
BrushLine.java 460B
icons
white多选框.png 133B
green多选框.png 131B
圆点大.png 260B
white多选框-选中.png 219B
yellow多选框.png 131B
圆点小.png 186B
圆点中.png 233B
ash多选框.png 131B
yellow多选框-选中.png 238B
download.png 550B
cancelx.png 348B
write.png 801B
blue多选框-选中.png 238B
box.png 304B
ash多选框-选中.png 237B
circle.png 472B
writing.png 231B
blue多选框.png 131B
圆点小1.png 189B
撤销.png 697B
圆点中1.png 228B
red多选框-选中.png 239B
圆点大1.png 238B
green多选框-选中.png 238B
red多选框.png 131B
finish.png 553B
captureScreen
filter
JPGfilter.java 452B
GIFfilter.java 481B
PNGfilter.java 463B
BMPfilter.java 498B
.idea
jarRepositories.xml 879B
ZeppelinRemoteNotebooks
uiDesigner.xml 9KB
libraries
Maven__commons_lang_commons_lang_2_5.xml 525B
workspace.xml 4KB
misc.xml 464B
compiler.xml 653B
modules.xml 273B
.gitignore 237B
aws.xml 304B
target
classes
MyScreenshotx$2.class 8KB
MyScreenshotx$5.class 1KB
MyScreenshotx$4.class 849B
MyScreenshotx.class 31KB
MyScreenshotx$1.class 5KB
icons
white多选框.png 133B
green多选框.png 131B
圆点大.png 260B
white多选框-选中.png 219B
yellow多选框.png 131B
圆点小.png 186B
圆点中.png 233B
ash多选框.png 131B
yellow多选框-选中.png 238B
download.png 550B
cancelx.png 348B
write.png 801B
blue多选框-选中.png 238B
box.png 304B
ash多选框-选中.png 237B
circle.png 472B
writing.png 231B
blue多选框.png 131B
圆点小1.png 189B
撤销.png 697B
圆点中1.png 228B
red多选框-选中.png 239B
圆点大1.png 238B
green多选框-选中.png 238B
red多选框.png 131B
finish.png 553B
MyScreenshotx$3.class 4KB
BrushLine.class 724B
captureScreen
filter
JPGfilter.class 782B
GIFfilter.class 786B
BMPfilter.class 790B
PNGfilter.class 786B
MyScreenshotx$6.class 933B
MyScreenshotx$2$1.class 2KB
com
intellij
uiDesigner
core
AbstractLayout.class 5KB
DimensionInfo.class 7KB
HorizontalInfo.class 2KB
Util.class 4KB
Spacer.class 547B
GridLayoutManager.class 19KB
VerticalInfo.class 2KB
GridConstraints.class 8KB
SupportCode$TextWithMnemonic.class 2KB
SupportCode.class 2KB
LayoutState.class 2KB
generated-sources
annotations
MyScreenshotx.iml 755B
共 94 条
- 1
资源评论
QinHuanJiDeWoMa
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功