e638. 向剪切板获取和粘贴图像
// If an image is on the system clipboard, this method returns it;
// otherwise it returns null.
public static Image getClipboard() {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); try {
if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
Image text = (Image)t.getTransferData(DataFlavor.imageFlavor);
return text;
}
} catch (UnsupportedFlavorException e) {
} catch (IOException e) {
}
return null;
}
Setting an image on the system clipboard requires a custom Transferable object to hold the image while on the clipboard.
// This method writes a image to the system clipboard.
// otherwise it returns null.
public static void setClipboard(Image image) {
ImageSelection imgSel = new ImageSelection(image);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null);
} // This class is used to hold an image while on the clipboard.
public static class ImageSelection implements Transferable {
private Image image; public ImageSelection(Image image) {
this.image = image;
} // Returns supported flavors
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[]{DataFlavor.imageFlavor};
} // Returns true if flavor is supported
public boolean isDataFlavorSupported(DataFlavor flavor) {
return DataFlavor.imageFlavor.equals(flavor);
} // Returns image
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (!DataFlavor.imageFlavor.equals(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
return image;
}
}
| Related Examples |
e638. 向剪切板获取和粘贴图像的更多相关文章
- e637. 向剪切板获取和粘贴文本
This examples defines methods for getting and setting text on the system clipboard. // If a string i ...
- 重新想象 Windows 8 Store Apps (40) - 剪切板: 复制/粘贴文本, html, 图片, 文件
[源码下载] 重新想象 Windows 8 Store Apps (40) - 剪切板: 复制/粘贴文本, html, 图片, 文件 作者:webabcd 介绍重新想象 Windows 8 Store ...
- 背水一战 Windows 10 (102) - 应用间通信: 剪切板
[源码下载] 背水一战 Windows 10 (102) - 应用间通信: 剪切板 作者:webabcd 介绍背水一战 Windows 10 之 应用间通信 剪切板 - 基础, 复制/粘贴 text ...
- js实现复制内容到剪切板,兼容pc和手机端,支持Safari浏览器
Javascript原生有一些事件:copy.paste.cut, 这些事件可以作用的目标元素: 能获得焦点的元素 (如contentEditable内容能编辑或者可以选中的元素),或者是<bo ...
- C#操作剪切板(Clipboard)
剪切板是Windows系统提供的功能,从我最早接触到的Windows 3.2版本开始,就一直带着了.以前使用C++的时候,是直接使用Windows API对其进行操作的,到了.NET下,在WinFor ...
- [转载]3.5 UiPath对剪切板的介绍和使用
一.剪切板操作的介绍 模拟用户使用剪切板操作的一种行为: 例如使用设置剪切板(SettoClipboard),从剪切板获取(GetfromClipboard)的操作 二.剪切板相关操作在UiPath中 ...
- Unity3d 复制文字到剪切板及存储图像到相册
游戏中里开发分享功能时用到两个小功能:1.复制一个链接到剪切板供在其他应用粘贴分享使用,2.保存一张二维码图像到相册供发送给其他应用用于分享.但是在unity中无法完成,需要分别开发相应的插件. An ...
- 浏览器中用JavaScript获取剪切板中的文件
本文转自我的个人网站 , 原文地址:http://www.zoucz.com/blog/2016/01/29/get-file-from-clipboard/ ,欢迎前往交流讨论 在网页上编辑内容 ...
- C++打开剪切板,获取剪切板数据
if (::OpenClipboard(NULL) && ::IsClipboardFormatAvailable(CF_HDROP)) { HDROP hDrop = (HDROP) ...
随机推荐
- NodeJS操作Redis实现消息的发布与订阅
首先先说一下流程: 1.保存数据到Redis,然后将member值publish到 chat频道(publish.js功能) 2.readRedis.js文件此前一直在监听chat频道,readRed ...
- ios网络层优化深入浅出
网络层是iOS开发必须掌握的部分,苹果已经将网络请求封装得非常易用了,看看NSURLRequest和NSURLConnection的文档,你就知道怎么用了,这里我就不细讲了.本文主要讲网络层的调用逻辑 ...
- html input select等控件宽度对不齐?请使用box-sizing。
今天终于明白为什么表单元素的宽度经常对不齐了,原来是计算的问题. 为元素设置:box-sizing: border-box;,则表明width的宽度为内容本身宽度+padding+border(高度一 ...
- Android开发之控制摄像头拍照
如今的手机一般都会提供相机功能,有些相机的镜头甚至支持1300万以上像素,有些甚至支持独立对焦.光学变焦这些仅仅有单反才有的功能,甚至有些手机直接宣传能够拍到星星.能够说手机已经变成了专业数码相机.为 ...
- U3D-LookAt插值动画
var qua = Quaternion.FromToRotation(Vector3.forward, target.transform.position - transform.position) ...
- win常用
//base.Invoke((MethodInvoker)delegate() //{ // this.Close(); //});
- 配置 logrotate 指导
一般来说,日志是任何故障排除过程中非常重要的一部分,但这些日志会随着时间增长.在这种情况下,我们需要手动执行日志清理以回收空间,这是一件繁琐的管理任务.为了解决这个问题,我们可以在 Linux 中配置 ...
- 如何创建自己的ruby gem包
编写一个最简单的例子 1. 建好如下文件夹 注意:lib目录下必须有个和你gem名字一样的rb文件. $ cd hola $ tree . ├── hola.gemspec └── lib └── h ...
- 【Util】之——cookie
拿走即用 使用前引入文件:http://files.cnblogs.com/ccto/util-cookie.js 使用方法: //设置cookie CookieUtil.set("name ...
- .net+jquery+ashx实现客户端模拟登陆扩展
客户端实现:login namespace LoginApp { partial class Form1 { /// <summary> /// 必需的设计器变量. /// </su ...