--- "bluescreenweasel" <peteraddington@...> wrote:
>
> what I needed was a "convert stdpicture to native dotnet image". The
> class you provided worked perfectly when i put it into my project. the
> thumbnail was returning a vague _com.obejct type, i needed to cast
> this into a stdole.stdpicture first.
>
> but i cant see if that's possible in the dotnet AIL? however, I would
> be converting stdpicture to AIL image then to dotnet image? is your
> included class better since im not performing any AIL functions? i am
> just returning the com.object thumbnail, converting to image and then
> putting it on a button.
If all you need to do is convert an StdPicture object to a
System.Drawing.Image object, then don't bother with AIL. It's not
designed to do that, nor does it have any functionality to do that...
though now that I think about it, it would be nice to include some
conversion functions like that in the .NET version.
1) Download this class and include it in your .NET project:
http://net.thevbzone.com/cStdOle.vb
2) Right click on your project in the "Solution Explorer" window and
select "Add Reference". When the dialog comes up, select "OLE
Automation" (C:\Windows\System32\stdole2.tlb) from the list and click
OK.
3) Double-click on your project's default form and put the following
code in the "Form1_Load" event handler:
Dim objImg As System.Drawing.Image
Dim objStdPic As stdole.StdPicture
' Load image from file as an Image
objImg = System.Drawing.Image.FromFile("C:\TEST.BMP")
' Convert the Image to an StdPicture
objStdPic = cStdOle.ConvertTo_StdPicture(objImg)
' Clean up the Image object
objImg = Nothing
' Convert the StdPicture object back to an Image
objImg = cStdOle.ConvertFrom_StdPicture(objStdPic,
cStdOle.ReturnTypes.rt_Image)
' Clean up the StdPicture object
objStdPic = Nothing
' Set the form's picture property to the image
Me.BackgroundImageLayout = ImageLayout.None
Me.BackgroundImage = objImg
========
Because you are explicitly typing the return as "stdole.StdPicture", it
should work for you.
- Kevin