For those who are unfamiliar or do not program in C# here is the VB interpretation:
Imports System.Windows.Forms
Imports System.Drawing
Imports Inventor
''' <summary>
''' This class performs the following conversion:
''' • Image to iPictureDisplay
''' • iPictureDisplay to Image
''' </summary>
''' <remarks>
''' You must Import the following namespaces.
''' • System.Drawing
''' • System.Windows.Forms
'''
''' Note:
''' If you are using WPF then you will need to add a reference to the "System.Windows.Forms" framework to your project.
''' </remarks>
Public NotInheritable Class IPictureDispConverter : Inherits AxHost
''' <summary>
''' This method is required to impliment the AxHost.
''' You do not need to modify this sub.
''' </summary>
Private Sub New()
MyBase.New("")
End Sub
''' <summary>
''' Converts a standard image to an IPictureDisp object.
''' </summary>
''' <param name="image">[Image] Image to convert to IPictureDisp</param>
''' <returns>[IPictureDisp] or Nothing on exception.</returns>
Public Shared Function ImageToPictureDisp(image As Image) As IPictureDisp
Try
Return DirectCast(GetIPictureDispFromPicture(image), IPictureDisp)
Catch ex As Exception
'Add error message or logging here if desired.
'Handle the conversion error by simply returning Nothing.
Return Nothing
End Try
End Function
''' <summary>
''' Converts an IPictureDisp object to a standard image file.
''' </summary>
''' <param name="pictureDisp">[IPictureDisp] IPictureDisp object to convert to image.</param>
''' <returns>[Image] or Nothing on exception.</returns>
Public Shared Function PictureDispToImage(pictureDisp As IPictureDisp) As Image
Try
Return GetPictureFromIPicture(pictureDisp)
Catch ex As Exception
'Add error message or logging here if desired.
'Handle the conversion error by simply returning Nothing.
Return Nothing
End Try
End Function
End Class
Below is a Visual Studio Item Template of the code.
Automation is key!