Reference post: CLIPBRD_E_CANT_OPEN error when setting the Clipboard from .NET
I already tried the methods in the thread above. But they didn't work. I asked a question there, and was directed to open a new question myself, hence here.
Basically, I turned a usercontrol into a RenderTargetBitmap. I am trying to pass the new RenderTargetBitmap object to the clipboard, so that other applications(suchs as paint/Word/Powerpoint) can use the image(similar to copy image on Google image).
I am running the application in Virtual Box and it seems that the Virtual Box is constantly accessing the clipboard. So, I used the code below but it took literally 10 seconds to finish copying to the clipboard. It also freezes the GUI at the same time. I tried async method, so that the GUI is not frozen. But it still takes around 10 seconds to finish copying to the clipboard. Then, I tried making a new thread. I set that thread to STA. But for some reasons, when I pasted the image to Paint, it said the information on clipboard cannot be inserted.
RenderTargetBitmap bmp = new RenderTargetBitmap(180, 180, 120, 96, PixelFormats.Pbgra32);
for (int i = 0; i < 10; i++)
{
try{
Clipboard.SetImage(bmp);
return;
}
catch(Exception e) { }
System.Threading.Thread.Sleep(10);
}
Any help is highly appreciated!