Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert System.Drawing.Bitmap to stdole.StdPicture

I have a System.Drawing.Bitmap currently and I need to convert it into an stdole.StdPicture.
Currently I'm using:

var pic = (stdole.StdPicture)Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture
                   (MyDLL.Properties.Resources.Img); // this is a System.Drawing.Bitmap

but I get a Compiler Warning:

Warning 'Microsoft.VisualBasic.Compatibility.VB6.Support.ImageToIPicture(System.Drawing.Image)' is obsolete: '"Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only. http://go.microsoft.com/fwlink/?linkid=160862

So what to use instead? I couldn't find another solution yet...

like image 975
Simon Woker Avatar asked May 24 '11 12:05

Simon Woker


1 Answers

taken from NetOffice http://netoffice.codeplex.com Office Addin Example

public class IconConverter : System.Windows.Forms.AxHost
{
   private IconConverter(): base(string.Empty)
   {
   }

   public static stdole.IPictureDisp GetIPictureDispFromImage(System.Drawing.Image image)
   {

      return (stdole.IPictureDisp)GetIPictureDispFromPicture(image);
   }
} 
like image 136
Homero Avatar answered Oct 21 '22 23:10

Homero