我有一个图片框,和,如果我使用snipet下面:

Clipboard.SetImage(PictureBox.image)

然后,我可以将图像仅粘贴到之类油漆和MS字。我不能将其粘贴作为一个文件到一个文件夹/桌面。

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

有帮助吗?

解决方案

<击>如果您在使用.NET和你的最终目标是要保存文件,有很多简单的方法,

下面的C#代码,将它移植到VB.net不会很难,我只是懒得做:) 无论如何,你必须保存在某个地方,然后才能将其粘贴等等...

它加载的文件的图片框,并再次将其保存到一个文件中,(瘸子,我知道)  并设置剪贴板数据作为复制操作

然后当你粘贴(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>

和中提琴尝试的文件图1.bmp将被粘贴在文件夹中粘贴。

其他提示

下面基本上什么@Vivek发布,但移植到VB。赞成票他,如果这对你的作品。你要明白什么是资源管理器将只允许你粘贴文件,而不是对象(据我所知反正)。究其原因是因为如果你的图像数据复制到剪贴板,应该它贴上什么格式? PNG,BMP,JPG?什么压缩设置?所以像@Vivek说,你需要在想那些,在系统上你自己的地方创建一个文件,并使用SetFileDropList将临时文件添加到剪贴板。

'   Add it as an image
    Clipboard.SetImage(PictureBox1.Image)

    'Create a JPG on disk and add the location to the clipboard
    Dim TempName As String = "TempName.jpg"
    Dim TempPath As String = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, TempName)
    Using FS As New System.IO.FileStream(TempPath, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.Read)
        PictureBox1.Image.Save(FS, System.Drawing.Imaging.ImageFormat.Jpeg)
    End Using
    Dim Paths As New System.Collections.Specialized.StringCollection()
    Paths.Add(TempPath)
    Clipboard.SetFileDropList(Paths)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top