copy image to clipboard and let it be pasted as file (vb.net)

clipboard, file, image, pasting, vb.net

Solution

If you're using .net and your ultimate goal is to save the file, there's a LOT easier way,

Here the code in C#, porting it into VB.net won't be hard, I'm just too lazy to do that :) Anyway, you do have to save it somewhere before you can paste it so...

It loads the file to the Picture box and again saves it to a file, (lame, I know) and set the clipboard data as a copy operation

then when you paste (Ctrl+V) it, it gets pasted.

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>

and viola tries pasting in a folder the file image2.bmp will be pasted.

Problem

I have a picture box, and if I use snipet below: ``` Clipboard.SetImage(PictureBox.image) ``` Then I can only paste the image into things like Paint and MS word. I can't paste it as a file into a folder/desktop. So how can I copy the image to the clipboard and if gets pasted to a folder then it becomes a file?

Original source