package com.image.capture; import java.awt.*; import java.awt.datatransfer.*; import java.awt.image.*; public class ClipboardUtil { private Clipboard cli; public void writeToClipboard(String str) { if (str != null) { cli = Toolkit.getDefaultToolkit().getSystemClipboard(); Transferable text = new StringSelection(str); cli.setContents(text, null); } } public void writeToClipboard(BufferedImage image) { cli = Toolkit.getDefaultToolkit().getSystemClipboard(); cli.setContents(new ImageChange(image), null); } public String getSysClipboardText() { String ret = ""; cli = Toolkit.getDefaultToolkit().getSystemClipboard(); // 获取剪切板中的内容 Transferable clipTf = cli.getContents(null); if (clipTf != null) { // 检查内容是否是文本类型 if (clipTf.isDataFlavorSupported(DataFlavor.stringFlavor)) { try { ret = (String) clipTf .getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { e.printStackTrace(); } } } return ret; } class ImageChange implements Transferable { private BufferedImage theImage; public ImageChange(BufferedImage image) { theImage = image; } public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.imageFlavor }; } public boolean isDataFlavorSupported(DataFlavor flavor) { return flavor.equals(DataFlavor.imageFlavor); } public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (flavor.equals(DataFlavor.imageFlavor)) { return theImage; } else { throw new UnsupportedFlavorException(flavor); } } } }

dearxo2014 LV1
2024年11月9日
fgg047 LV1
2022年1月24日
laowang933 LV1
2021年5月3日
2196316269 LV10
2020年11月21日
675104182 LV14
2020年9月22日
天空java LV8
2020年6月1日
wngauss LV4
2020年5月22日
SKxumeng LV1
2019年5月28日
鱼椒盐排骨 LV8
2019年5月27日
blb555 LV14
2019年5月26日

dearxo2014 LV1
2024年11月9日
sswert LV2
2024年9月12日
3334004690 LV10
2024年6月6日
ja12121 LV2
2023年6月17日
微信网友_5992582549164032 LV6
2023年2月21日
maoye520 LV1
2022年8月10日
fantaohaofan LV2
2022年6月23日
977903096 LV10
2022年3月12日
fgg047 LV1
2022年1月24日
laowang933 LV1
2021年5月3日