Reputation: 1
Hi i got form that reads eID card, smart cards text data reads correctly picturebox name is picLK but last statement is a picture
in VB6 and VBA I used
me.pctLK.Picture = ReaderEngine.portrait
ReaderEngine is procedure that reads data from card
when I use command in vb.net I get an error
me.pctLK = ReaderEngine.portrait
reader is reading card, but I got this message
An unhandled exception of type '
System.InvalidCastException
' occurred in Project1.exeAdditional information: Unable to cast COM object of type '
stdole.StdPictureClass
' to class type 'System.Windows.Forms.PictureBox
'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
I am new to VB .net
Is there any suggestions?
Upvotes: 0
Views: 165
Reputation: 155726
VB.NET has a helper function in the Microsoft.VisualBasic.Compatibility.VB6.Support
module, named IPictureDispToImage
, which accepts an StdPictureClass
object (which implements IPictureDisp
) and returns a .NET System.Drawing.Image
object which you can assign to the PictureBox.Image
property. Be sure you appropriately dispose of the Image
when you're finished with it:
Dim comImage As StdOle.StdPictureClass = ReaderEngine.portrait
If Me.picLK.Image Is Not Nothing Then
Me.picLK.Image.Dispose()
Me.picLK.Image = Nothing
End If
Dim newImage As System.Drawing.Image = Support.IPictureDispToImage( comImage )
Me.picLK.Image = newImage
Upvotes: 0