/** * 复制图片到剪切板。 */ public static void setClipboardImage(final Image image) { Transferable trans = new Transferable() { public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.imageFlavor }; } public boolean isDataFlavorSupported(DataFlavor flavor) { return DataFlavor.imageFlavor.equals(flavor); } public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (isDataFlavorSupported(flavor)) return image; throw new UnsupportedFlavorException(flavor); } }; Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trans, null); } public static void main(String[] args){ URL url; try { url = new URL("//192.168.2.100:8080/sss/images/copyright.jpg"); //载入图片到输入流 java.io.BufferedInputStream bis = new BufferedInputStream(url.openStream()); / InputStream is=new FileInputStream(file); BufferedImage bi=ImageIO.read(bis); Image im=(Image)bi; setClipboardImage(im); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException s) { // TODO Auto-generated catch block s.printStackTrace(); } }
本文标题:JAVA如何复制图片到剪切板,责任编辑:宏鹏,来源:武汉北大青鸟鲁广校区栏目,于2012-12-25 13:54:50发布于北大青鸟鲁广校区。JAVA如何复制图片到剪切板,先要复制图片到剪切板,然后载入图片到输入流。不是图片,文件也可以套用这些方法。
预约将免费领取7天课程体验卡
只为您方便就学
专业老师24小时1对1学习指导
定制专属于你的专属学习方案
微信号:17740513250
微信号:17740513250