Problem trying to load an image into a PictureBox

Problem trying to load an image into a PictureBox

Anonymous
Not applicable
1,568 Views
7 Replies
Message 1 of 8

Problem trying to load an image into a PictureBox

Anonymous
Not applicable

I'm trying to convert a VBA application to .Net.

 

First things first: AutoDesk's .Net implementation sucks and the lack of cohesive documentation is pathetically shameful. Why should I have to search far and wide to try and get enough information to make this crap work? This situation is unconscionable. And yet here we are, years after release, and they still don't have their crap together on this. Seems like everything about AutoCAD is steadily going downhill. It used to be a professional quality package. Now, it is rife with problems that the company ignores and it has absolutely the WORST documentation of the API of any professional product I have ever seen.

 

My latest go-around with this travesty:

 

I need to load a PictureBox with an image from a file at runtime.

 

PictureBox1.Image = Image.FromFile("Image.bmp")

-> Results in the error: 'FromFile' is not a member of 'Autodesk.AutoCAD.DatabaseServices.Image'.

Huh? This is how Visual Studio tells me to load an image. I guess AutoDesk thought better of it.

 

PictureBox1.Image.FromFile("Image.bmp")

-> Results in the error: 'Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.'

 

These examples were both taken directly from Visual Studio's help. Does anybody know of an approach that works?

 

 

0 Likes
Accepted solutions (2)
1,569 Views
7 Replies
Replies (7)
Message 2 of 8

Hallex
Advisor
Advisor
Accepted solution

Have you tryed:

Imports System.Drawing

--------------------------

PictureBox1.Image = System.Drawing.Image.FromFile("Image.bmp")?

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 8

Anonymous
Not applicable

I thought I had tried that using IntelliSense to guide me, but it didn't work that way. Just putting it in manually seemed to do the trick. Thanks!

 

0 Likes
Message 4 of 8

Anonymous
Not applicable

Try the attached class. Works fine on 2007 and 2008 on 32 and 64 bits machines.

I use it to provide previews of DWGs of dynamic blocks and other blocks that are not currently opened.

I use it this way combined with a list box with the full names of the dwgs

 

string myDWGPath = Path.Combine(FileServer, listBoxProfiles.Text);
Bitmap dwgThumb = ThumbnailReader.GetThumbnail(myDWGPath,false);
      pictureBox.Image = dwgThumb;
      if (dwgThumb != null)
      {
        // whatever you like
      }
      else
      {
        // whatever exception handling you like
      }

0 Likes
Message 5 of 8

chiefbraincloud
Collaborator
Collaborator
Accepted solution

It's obvious that you have Imported Autodesk.AutoCAD.DatabaseServices, and have not imported System.Drawing.  If you do Import System.Drawing, then the Image reference will be ambiguous, existing in both System.Drawing, and Autodesk.AutoCAD.DatabaseServices.

 

You just need to explicitly specify the System.Drawing.Image

 

PictureBox1.Image = System.Drawing.Image.FromFile("Image.bmp")

Dave O.                                                                  Sig-Logos32.png
0 Likes
Message 6 of 8

Anonymous
Not applicable

Thanks, ognyandim, but you seem to have replied to the wrong topic...

0 Likes
Message 7 of 8

Anonymous
Not applicable

That explains my problem.

 

Thanks, guys.

0 Likes
Message 8 of 8

Anonymous
Not applicable

You can get a thumb from you file either with the same class. It doesnt matter if it is DWG or JPG, or BMP or whatever. You can strech yout thumb to whatever size you want after you get it.

0 Likes