I am new to VB.NET.
I have a simple Visio add-in that has a TreeView1 control on it. I am trying to display the image of the shapes in the nodes of the TreeView.
For this, I have ImageList1 control but I am really stuck in the following:
TreeView1.ImageList = ImageList1
TreeView1.ImageList.Images.Add(shp.NameID, shp.Picture) ' for Add(key As String, image As System.Drawing.Image) ' ERROR HERE
TreeView1.Nodes.Add(shp.NameID, shp.Name, shp.NameID) ' for Add(key As String, text As String, imageKey As String)
Ok, the type of shp.Picture is stdole.IPictureDisplay and the Add function of ImageList expects a parameter of type System.Drawing.Image but how to convert stdole.IPictureDisplay to System.Drawing.Image ? ? ?
I have used many codes posted on the internet without a success.
Does anybody knows how to do this. Please post the code (that really works please) rather than provide links to other sites.
I really would appreciate this help.
Yousuf
Hello Yousuf,
maybe you can use the Shape.Export method to save the shape to an image file. Then you can use .NET's Image.FromFile() method to create an image.
Thanks for the suggestion charlykuntz.
This approach is not feasible for the thing i want to achieve from the Add-in as this is VERY slow. There are thousands of shapes that i need to convert their images from stdole.IPictureDisplay of Shape.Picture to System.Drawing.Image.
Yousuf.
Hmmm... Haven't you suggested a solution two years ago?? :)
http://visguy.com/vgforum/index.php?topic=1987.msg11929#msg11929
Actually, in that post, I quoted JuneTheSecond's post which was based on your code! ;D
Yes, I asked a similar question but it was for VBA not VB.NET.
Now that I converted your C# code to VB.NET code:
Dim picptr As IntPtr = New System.IntPtr(shp.Picture.Handle)
Dim img As System.Drawing.Image = New System.Drawing.Imaging.Metafile(picptr, True)
Dim bmp As System.Drawing.Bitmap = New System.Drawing.Bitmap(img)
TreeView1.ImageList.Images.Add(shp.NameID, bmp)
Note that i had to create an object for a pointer to shp.Picture.Handle as the direct cast (System.IntPtr)shp.Picture.Handle did not work.
and this Did solve my problem. Thanks a lot.
As usual, you are a star Nikolay. 8)
Hello,
I am working with a software developer on a Visio plugin. They generate an image of a shape as a reference but it seems that my Master shapes that have text in them... the text blows up and messes up the end result. I am trying to find out what method they are using to get the image. But does that ring any bells?
Thanks for any help.
Q