允许用户从图片框中复制图像并将其保存在任何地方 [英] Allow user to copy image from picturebox and save it everywhere

查看:174
本文介绍了允许用户从图片框中复制图像并将其保存在任何地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个显示图像的 pictureBox 。当用户右键单击 pictureBox 并从上下文菜单中选择复制时,我想将图像复制到剪贴板中因此用户可以将其粘贴到文件夹和其他任何地方。我怎样才能做到这一点?

In my application I have a pictureBox that shows an image. When user right clicks on the pictureBox and selects Copy from the context menu, I want to copy the image into the clipboard so the user can paste it in folders and anywhere else. How can I do that?

编辑:我使用此代码,但此用户只能将图片粘贴到文字中。

I use this code but by this user only can paste image into word.

var img = Image.FromFile(pnlContent_Picture_PictureBox.ImageLocation);
Clipboard.SetImage(img);


推荐答案

Clipboard.SetImage 将图像内容(二进制数据)复制到剪贴板而不是文件路径。要在Windows资源管理器中粘贴文件,您需要在剪贴板中收集文件路径而不是其内容。

Clipboard.SetImage copies the image content (binary data) to the clipboard not the file path. To paste a file in Windows Explorer you need to have file paths collection in the clipboard not their content.

您只需将该图像文件的路径添加到 StringCollection 然后调用 剪贴板 SetFileDropList 方法来实现你的目标想要。

You can simply add the path of that image file to a StringCollection and then call the SetFileDropList method of Clipboard to achieve what you want.

System.Collections.Specialized.StringCollection FileCollection = new System.Collections.Specialized.StringCollection();
FileCollection.Add(pnlContent_Picture_PictureBox.ImageLocation);
Clipboard.SetFileDropList(FileCollection);

现在用户可以在任何地方通过文件,例如Windows资源管理器。

Now user can past the file anywhere e.g. Windows Explorer.

关于的更多信息Clipboard.SetFileDropList方法 http://msdn.microsoft.com/en-us/library/system.windows.forms。 clipboard.setfiledroplist.aspx

这篇关于允许用户从图片框中复制图像并将其保存在任何地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆