Picture This

1 Apr, 2004 By: Bill Fane

Don’t overlook image files when working in AutoCAD.

It was a dark and stormy night. Captain LearnCurve and his gorgeous wife were packing up for their annual Caribbean pilgrimage to do a bit of scuba diving. They had checked all their gear, including the underwater case for the digital camera. Suddenly his acute hearing picked up a plaintive cry:

"Oh woe is me! I have a picture that I want to see inside an AutoCAD drawing, but obviously AutoCAD works with lines, circles, and so on. Whatever shall I do?"

Fear not, hapless AutoCAD user -- help is at hand!

Two Kinds of Graphics Files
The most common type of graphics file is the raster image, which gets its name from the way an image is formed on a TV screen or computer monitor. Its presence is much more obvious when you look closely at an old black-and-white TV screen. You'll see that the picture is formed from 512 horizontal lines. Each line gets lighter and darker as it proceeds from left to right, so that when all the lines are stacked up, the light and dark areas align to build the image. This horizontal line pattern is known as a raster.

Color TVs and computer monitors work the same way, but it's not quite as obvious because each horizontal line is composed of a series of colored dots -- about 650 dots in a standard TV. A typical computer monitor uses 1024 dots in 768 lines, or whatever other resolution is specified.

When you save a raster image to disk, its file contains a list of the color of each dot. You can save the file in a number of formats, including BMP, GIF, JPG, and so on, but they all accomplish the same thing. The image files have no particular intelligence -- a line on screen is simply an appropriate alignment of dots.

On the other hand, all CAD systems, including AutoCAD, save their data to disk as a vector file. In such a file, a line has a start, an end, and a layer. Its properties can be altered and the results update on screen.

A Word Is Worth 0.001 of a Picture
There are times when a raster scan image can be useful within an AutoCAD drawing. For example, you may have an existing paper drawing that you need to convert to a CAD version. You can scan the paper drawing to a raster file, insert the raster file into an AutoCAD drawing, and simply trace over it with lines, arcs, circles, and so on.

Raster images can also be used to add a fancy company logo to a title block, to provide the panoramic background for an architectural presentation, or to show the existing setting in a factory along with an AutoCAD drawing of a proposed new piece of machinery. I've even seen people scan an existing physical part, then insert the image and draw over it to reverse-engineer it to produce a drawing file. The possibilities are endless.

In AutoCAD, inserting and manipulating raster images is quite simple. We'll walk through an example, and then look at some of the details.

Start the ImageAttach command by clicking on Insert/Raster Images, which brings up the Select Image File dialog box (figure 1). Browse to a suitable folder and find an image file. If you don't have anything of your own, there are some interesting samples in C:\WINDOWS\WEB\WALLPAPER or in C:\WINNT\WEB\WALLPAPER, depending on your Windows version. By default, the Select Image File dialog box shows a preview when you single-click on an item, so it's easy to find what you want.

Figure 1. Find a suitable image to insert.

Choose a suitable image, and click Open or double-click the filename. The Image dialog box in figure 2 appears.

Figure 2. The Image dialog box.

Hey, this looks suspiciously like the Block Insertion dialog box! Make sure all three Specify On-screen boxes are unchecked, as shown in figure 2, and click OK.

The dialog boxes retreat, and you return to your AutoCAD drawing. Depending on the image you chose, you may have to do a Zoom All to see your image. Figure 3 shows the full AutoCAD screen with an image file inserted into the drawing.

Figure 3. AutoCAD with a suitable image file inserted into the drawing.

Okay, so what do we have? A bit of experimentation reveals that this is a single object, much like a block insertion. Click on its boundary frame to select it. You can Move, Copy, Erase, Rotate, and so on, just like any other single object. Grip editing or the Stretch command lets you stretch it bigger or smaller, but the same aspect ratio is always maintained between the width and height.

Anything you draw after inserting it is drawn over it (figure 4).

Figure 4. You can draw over an image with standard AutoCAD objects.

You can turn the image off and on by freezing and thawing the layer it's on, and you can click Tools/Display Order (see The Learning Curve, July 2003; to bring it to the front or push it to the back.

A frame surrounds the image, and you select the image by clicking on its frame. If IMAGEFRAME is set to Off, all the frames are invisible, so you can't select an image to edit or relocate it. This can be useful to prevent accidental movement.

The IMAGEHLT system variable controls how the image highlights when selected. When set to the default of 0 (zero), only the frame highlights, whereas a setting of 1 causes the entire image to highlight.

Now let's go back and review some of the options, starting with the list of supported file types. By default, the Select Image File dialog box in figure 1 defaults to showing all supported file types. Click on the scroll list to see the specific formats that are supported. As you can see, it includes virtually all of the common formats. Interestingly, it displays the file names based on their extension, but when it opens a file it determines the format from the actual file contents. Even more interestingly, this list is longer than the one in the Help facility.

Now let's look at the options in the Image dialog box of figure 2.

As previously noted, it looks almost exactly like the Block Insertion dialog box. The function of the Insertion Point and Rotation regions should be obvious, but Scale needs a bit of discussion.

AutoCAD determines the width of the image frame in drawing units by multiplying your supplied scale factor times the scale factor determined from the image file. The fun bit here is that not all image files contain an internal scale factor, and this isn't dependent on file format. Some images have a scale factor, while others of the same format don't. If a file doesn't contain a scale factor, AutoCAD assumes it's one.

Note also that AutoCAD bases the image frame size solely on scale factors and not on the image file's pixel resolution. A 320X200 file and a 1024X768 file, both with no internal scale factor and both inserted at a scale factor of one, produce images in the drawing that are one unit wide. This requires a bit of experimentation to get things right.

What Could Possibly Go Wrong, Go Wrong, Go Wrong . . .
The main point to remember is that a raster image never actually becomes part of the AutoCAD drawing. It's attached as an external reference, just like a block xref and all this implies. The first and most significant implication is that the raster file must be available whenever the drawing file is open. If it's not, AutoCAD replaces it with a simple rectangle containing the name of the missing file. You may want to rethink using one for your company logo if your files regularly leave your premises.

The next implication is that the path to the raster file is usually contained within the drawing file. If you move things to a different drive or folder, or send the files to someone who uses a different folder structure, things won't match, and you'll get the "rectangle of lost files" again.

I said "usually" earlier, because that's the default setting of the Retain Path button in the Image dialog box of figure 2. If you uncheck this box, the host file saves just the name of the image file and forgets its path.

There are advantages and disadvantages to both settings. Let's start with the default setting to save the path.

Next time you open the host drawing, it looks for the image file at the specified location. If it can't find it there, it looks in the same folder as the host drawing. If it can't find it there, it gives up and displays the "rectangle of lost files."

On the other hand, if you told it not to save the path, the host drawing looks in the same folder as the host. If it can't find it there, it will search AutoCAD's current Support File Search Path list. To see this list, click on Tools/Options/Files and expand the Support File Search Path. The bad news is that the drawing latches onto the first file whose name matches, whether it's the correct one or not, and may not even look for it in the original folder.

In summary, it's usually best to save the path when you want the drawing to find an exact, specific image file, particularly if its use is unique to the current drawing and if the path structure is not likely to change.

On the other hand, it's better to not save the path for generic images applied to multiple drawings, such as a company logo in a title box. Simply put the image file somewhere in the AutoCAD search path, perhaps on a network, and you'll always be able to find it.

So, what if you change your mind, or if AutoCAD can't find the desired file? No problem! Simply start the Image command by clicking on Insert/Image Manager to bring up the Image Manager dialog box in figure 5.

Figure 5. The Image Manager dialog box.

The operation of this dialog box is intuitive. You can click on the following:

  • Attach, which attaches another image to the drawing. This invokes the ImageAttach command we saw earlier.
  • Detach, which deletes the image from the drawing and breaks the link to it.
  • Reload, which re-reads the image file on disk and refreshes the image in the drawing.
  • Unload, which replaces the image in the drawing with a simple rectangle, but retains the link to the file. Reload brings it back.
  • Details, which tells you all about the file: its type, resolution, and so on.
The Image Found At window and its two buttons are interesting. You can use them to browse to and load a missing file, replace one image file with another, and turn Save Path on or off.

Image files are often overlooked in AutoCAD, because we're used to using it only as a vector tool. As you've seen, however, image files are easy to insert and manipulate, and can be powerful tools in your arsenal.

And Now for Something Completely Different
There are 10 kinds of people in the world: those who understand binary and those who don't.

AutoCAD Tips!

Lynn Allen

In her easy-to-follow, friendly style, long-time Cadalyst contributing editor and Autodesk Technical Evangelist Lynn Allen guides you through a new feature or time-saving trick in every episode of her popular AutoCAD video tips. Subscribe to the free Cadalyst Video Picks newsletter and we'll notify you every time a new video tip is published. All exclusively from Cadalyst!

Follow Lynn on TwitterFollow Lynn on Twitter

Which device do you typically use to read content?
A desktop computer / tower workstation
A tablet
A smartphone
A laptop or mobile workstation
I regularly use both a desktop computer and a smartphone for this purpose
I regularly use another combination of devices for this purpose
I prefer to print out articles from the website and read them on paper
Submit Vote

Download Cadalyst, Fall 2015

Download Cadalyst Magazine Special Edition