将图像复制到剪贴板并将其粘贴为文件(vb.net)

Jon*_*an. 3 vb.net clipboard image file pasting

我有一个图片框,如果我使用__CODE__那么我只能将图像粘贴到Paint和MS word之类的东西上.我无法将其作为文件粘贴到文件夹/桌面.

那么如何将图像复制到剪贴板,如果粘贴到文件夹,那么它就变成了文件?

Viv*_*ard 5

如果您使用的是.net,并且您的最终目标是保存文件,那么更简单的方法,

这里的代码用C sharp,将它移植到VB.nt中不会很难,我只是懒得这样做:)无论如何你必须把它保存在哪里才能粘贴它所以......

它将文件加载到图片框并再次将其保存到文件中(跛脚,我知道)并将clipbaord数据设置为复制操作

然后当你粘贴(Ctrl + V)它时,它会被粘贴.

C#
__
    Bitmap bmp;
    string fileName=@"C:\image.bmp";
    //here I assume you load it from a file, you might get the image from somewhere else, your code may differ

pictureBox1.Image=(Image) Bitmap.FromFile(fileName); bmp=(Bitmap)pictureBox1.Image; bmp.Save(@"c:\image2.bmp"); System.Collections.Specialized.StringCollection st = new System.Collections.Specialized.StringCollection(); st.Add(@"c:\image2.bmp"); System.Windows.Forms.Clipboard.SetFileDropList(st); </pre>
Run Code Online (Sandbox Code Playgroud)

和中提琴尝试粘贴文件image2.bmp粘贴文件夹.