6

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...

Rais Alam
  • 6,970
  • 12
  • 53
  • 84
Simon Woker
  • 4,994
  • 1
  • 27
  • 41

2 Answers2

8

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);
   }
} 
Simon Woker
  • 4,994
  • 1
  • 27
  • 41
Homero
  • 236
  • 1
  • 2
  • You find more details in the original post where the above has been copied from: https://blogs.msdn.microsoft.com/andreww/2007/07/30/converting-between-ipicturedisp-and-system-drawing-image – Elmue May 22 '17 at 22:23
  • 1
    For those who are wondering what is "stdole": You find it in Visual Studio Solution Explorer -> Refecence -> Add Reference -> .NET -> stdole – Elmue May 23 '17 at 18:50
0

If you do a Google search for [convert .net image to ole picture], you'll find a whole lot of chatter about going the other way (i.e. converting an ole picture to image), and a lot of advice that says, in effect, "don't try to use ole pictures in .NET". I concur. I went down that path a few years ago and decided that I didn't really need the OLE picture that badly.

I strongly recommend that you re-evaluate your need for OLE picture objects. If you're saving images in a database, store them as BLOBs rather than as picture objects. If you absolutely have to use OLE picture objects, then good luck. It's going to be very frustrating.

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • 1
    It seems a lot of people need to do this in the callback of loadImage to customize ribbon button images. The signature of the callback is `Public Function OnLoadImage(imageId As String) As IPictureDisp` Do you have a suggestion on how to solve that? – Fuhrmanator Feb 17 '14 at 05:27