Using Bitmaps (Also Known As Raster Graphics)

 < Day Day Up > 

In this section you'll see how bitmap (raster) graphics can be used in Flash. Raster graphics have inherently unique characteristics that can't be created inside Flash. The only warning related to using this option is to make sure you really need raster graphics. The following are some cases that justify the use of raster graphics:

  • A photograph. The only time to consider using a vector alternative to a photograph is when the picture is of a very geometric object. Otherwise, photographs should be raster graphics.

  • A series of still images extracted from frames of a short video.

  • An image with special effects that can't be achieved by using a vector tool, such as clouds, fire, water, and other natural effects. (Of course, this is an invitation for a talented artist to re-create such an effect by using a vector tool such as Flash.)

If you're unfamiliar with the difference between vector graphics and raster graphics, learning when one choice is better than the other can take some time. The file formats .gif, .jpg, .png, .bmp, and .pct are all raster graphics formats. However, just because a file was saved in one of these formats doesn't mean it was done appropriately. It's the nature of the image in the file that matters. If all you have is a .gif, for example, you need to first look at its contents to judge whether it's appropriate for raster graphics. Here's an easy way to decide: If you can trace or redraw the image in the file (with Flash's drawing toolbar, for instance), you're much better off redrawing it. If it's a photograph, you would never be able to trace it (so leave it as a raster graphic). If it's a picture of a plain box, maybe you could draw it and thus take advantage of all the benefits of vector graphics without even bothering with raster graphics.

Importing Raster Graphics

Importing a raster graphic is pretty simple to do. You just select File, Import, Import to Stage, to open the Import dialog box and then point to any raster graphic that Flash supports: .jpg, .png, .gif, .bmp, or .pct. That's it. (In fact, Flash imports a few other esoteric formats such as Photoshop version 2.5 but the five listed here are by far the most popular.)

However, importing not only places the graphic on the Stage but also puts a master bitmap item into the Library. If you import a raster graphic and then delete the object from the Stage, the master bitmap item will still be in the Library (which you can find by selecting Window, Library). It's called a bitmap item, and it has a little icon that looks like a picture of a tree (as shown in Figure 3.6).

Figure 3.6. After you import a raster graphic, the bitmap item will appear in your Library.


After a raster graphic is imported, you need to keep it in the Library. The bitmap icon that appears in the Library provides a way to specify how the image should be exported when you create a movie for the Web. If you leave it unchanged, your raster graphics will export using the default settings. You can also specify special settings for just that image. In the following task you'll import a raster graphic and explore some of these settings.

Try It Yourself: Import a Raster Graphic>

In this task you'll import a raster graphic. Here are the steps:

1.

In a new file, select File, Import, Import to Stage, to open the Import dialog box and then select a .bmp, .pct, .png, .jpg, or .gif file. If you don't have an image handy, just visit any web page and right-click an image to select an option to save it on your desktop. Then use that image as the file to import into Flash. Note that you probably don't want to import an image saved directly from a digital camera because it's probably huge.

2.

Click the graphic on the Stage and delete it. Because it's a raster graphic, it's still safely in the Library.

3.

Open your Library by selecting Window, Library or by pressing Ctrl+L.

4.

Click the line in your Library that has the tree icon and the name of the file you imported.

5.

In the Library, select Options, Properties. (The Options menu is inside the Library window at the top right.) The Bitmap Properties dialog box shown in Figure 3.7 appears. (This dialog box might look slightly different, depending on what type of file you imported.)

Figure 3.7. The Bitmap Properties dialog box offers control over how each bitmap item in your Library will be treated during export.


6.

In the Bitmap Properties dialog box, decide what export settings to use for this graphic. (Leave this dialog box onscreen while you walk through the next section.)

Adjusting Bitmap Properties

Flash imports all kinds of raster formats but only uses JPG, GIF, or PNG in an exported movie. In addition, any raster graphic is generically called a bitmap item once inside Flash's Library. This means that no matter what file type you import, you must use the Bitmap Properties dialog box to choose between JPEG (and its compression level) and lossless GIF/PNG for exporting. You can experiment with the Bitmap Properties dialog box and click the Test button after each change to see the effects on both image quality (in the little picture at the top left) and file size (in the text information at the bottom of the dialog box). See Figure 3.8. The process involves experimentation making adjustments and viewing the corresponding results.

Figure 3.8. Selecting a low JPEG compression (10) and clicking Test provides a preview of the resulting image and its file size.


JPEG compression is usually the most efficient option. Unless you import a .png or .gif, Flash sets the bitmap properties to JPEG by default. It's slightly confusing because if you import a .jpg file, Flash uses Imported JPEG Data by default, as shown in Figure 3.9. This option tells Flash to maintain the imported file's original compression (that is, don't recompress). Leaving this option selected is generally desirable because it's a bad idea to recompress.

Figure 3.9. Only imported .jpg files enable you to use the JPEG compression contained in the original file.


Watch Out!: Three Ways to Use Imported Raster Graphics

There are three suitable approaches to using raster graphics in Flash. First, you can start with the highest-quality image possible (for instance, .png, .bmp, or .pct) and then experiment with Flash's JPEG compression to find the best compromise. Second, you can import a .bmp, .png, or .pct and leave the image uncompressed; this gives you the highest quality and also the largest file size. This is also the only option to maintain a .png's transparency settings. Finally, you can use image editing software such as Fireworks to create a .jpg file with the best compromise (of file size and quality) that can be imported into Flash. This way you can take advantage of the Selective JPG feature in Fireworks. If you use this option, you need to remember to leave the Use Imported JPEG Data option selected. If the image has already been compressed (using JPEG compression), you shouldn't allow Flash to recompress because the result would be a poor-quality image.


Importing other popular formats, such as .bmp and .pct, also causes Flash to opt for JPEG compression by default. However, the Bitmap Properties dialog box displays a different option: Use Document Default Quality, as shown in Figure 3.10. Although this looks similar to the Use Imported JPEG Data option discussed earlier, it's a different option entirely. Leaving this option selected causes Flash to use a global setting to compress the file. The global settings are made when you publish the movie. These topics are discussed in more detail in Hours 21 and 24.

Figure 3.10. When you import non-.jpg files, you can use the global (default) quality settings for the whole Flash file.


You can control what compression method is used on individual imported images by simply deselecting Use Document Default Quality (or deselecting Use Imported JPEG Data for that matter but keep in mind the earlier caution about recompression). When this option is deselected, a field appears where you can type the JPEG compression level you desire. Instead of guessing what compression level is best, you can use the Bitmap Properties dialog box to experiment. A lower number results in a smaller file but also lowers the quality. If you click Test after each change, you see a drastic difference between 100 and 1. After you make each change, you can click the Test button to review the effect on file size and quality, as shown in Figure 3.11. You should experiment until you get the best compromise of image quality and file size.

Figure 3.11. Setting the quality to 10 cuts this image size to less than 1/100 of its original, but the quality is visually affected.


The image portion shown in the image window at the top left of the Bitmap Properties dialog box shows exactly how the image will look when it is exported. You can zoom into this window by right-clicking and then you can pan around to get a better view.

Figure 3.12 shows the results of using several different compression levels on the same image. Notice that JPG 80 and JPG 100 are almost identical in quality, but JPG 80 has a much smaller file size.

Figure 3.12. The results of different compression settings on the same image shows how quality degrades and file size shrinks.


You get the ultimate quality by using the compression option Lossless (GIF/PNG). It is selected by default when you import .png and .gif files, but you can select it any other time you want to use it. When this option is selected, Flash leaves the image in its original state. This option always provides the best quality but not without a price. File size is always highest when this option is selected. This is a suitable alternative if you're making a movie that doesn't need to download from the Web maybe if you're just making a presentation you'll deliver on your hard drive or CD-ROM. Otherwise, you should use this option only on images that you want to retain the best quality possible. If your imported image is a .gif that already has a small file size, selecting Lossless is perfectly suitable. And because even 100% JPEG compression causes some image degradation, the Lossless option is suitable for images that are particularly important. Finally, the only way Flash supports 32-bit graphics (that is, raster images with varying degrees of transparency) is through .png items that you set to Lossless. That is to say, the fact that PNG is the only format that supports transparency is another perfectly legitimate reason to use PNG.

Converting a Bitmap to a Vector Graphic

Two common situations call for converting a bitmap into a vector graphic. The first is when you have a raster file that would be more suitable as a vector graphic (so you would like to take advantage of what vectors offer). The second, and more likely, time is when you want to create a special effect, such as a posterized look or an outlined effect.

In the following task you'll convert a raster graphic to a vector graphic. In Windows, you'll import the pinstripe image that is provided as a desktop pattern.

Try It Yourself: Convert a Bitmap to a Vector

In this task you'll use Flash's Trace Bitmap feature to convert a bitmap into a vector graphic. Here are the steps:

1.

In a new file, select File, Import, Import to Stage, to open the Import dialog box and point to a raster graphic that contains the most geometric shapes you can. (You can also import one I have available at www.phillipkerman.com/teachyourself.)

2.

Zoom in on the graphic so that you can see what a bitmap looks like close up. It should look grainy, like the image in Figure 3.13. Obviously, this image wouldn't scale well, which is a characteristic of bitmaps.

Figure 3.13. A bitmapped image looks grainy when you scale it or zoom in on it.


3.

With the object selected, choose Modify, Bitmap, Trace Bitmap. In the Trace Bitmap dialog box that appears (as shown in Figure 3.14), enter 1 in the Color Threshold field. This indicates how close two colors must be in order to be considered the same color. Minimum Area specifies how small the smallest vector shape can be. Set this at 10. Leave Curve Fit and Corner Threshold set to Normal. (You'll see how they work in a minute.) Click OK.

Figure 3.14. The Trace Bitmap dialog box lets you specify how tracing will occur.


4.

The graphic is now all vector shapes. The stripes on the edge might be bent, and you might see some weird artifacts on the top or bottom (which can be fixed). Even so, the graphic not only looks as good as the original, it looks better especially if you need to scale to a larger size.

By the Way: Artifacts

An artifact is any unwanted or obscure result of a process. For example, static on the radio is an artifact of transmission. Moire patterns in magazine pictures, color shifts on TV, raindrops on a camera lens, and typos in books are all examples of artifacts. Flash's Trace Bitmap feature sometimes leaves artifacts. JPEG compression also leaves artifacts, which are most noticeable when you set the quality to a low number.


With its nice, clear geometric shapes, the image I selected for the preceding task is particularly well suited to conversion to a vector graphic. Sometimes it's not easy for Flash to convert a graphic to a vector graphic because the image is too intricate. Other tools that are especially designed for these types of conversions, such as the Live Trace feature in Adobe's Illustrator CS2, use more sophisticated processing methods. However, before you give up on this feature, you should experiment with the settings in the Trace Bitmap dialog box. The Help button provides details about each setting.

The Trace Bitmap dialog box (refer to Figure 3.14) has several interesting options:

  • Color Threshold When you're tracing an image, Flash tries to lump areas of the bitmap into single shapes. The Color Threshold option specifies how different two colors can be (in RGB values) and still be considered the same. If you set this option to a high number, you will end up with fewer colors and fewer areas.

  • Minimum Area This option specifies the smallest area Flash will create. For a very detailed image, this number should be set rather low, unless you want a mosaic effect.

  • Curve Fit This option affects how closely straight and curved areas will be copied. Using the Very Smooth end of the Curve Fit scale is like having a very large pen with which to draw a shape in one quick movement. If you could use a fine pencil and as many strokes as needed, that would be like the other extreme, Pixels or Very Tight.

  • Corner Threshold This option determines whether corners are left alone or removed.

In addition to converting a bitmap to a vector graphic, you can "vectorize" a bitmap for an artistic effect. It just takes experimentation. Keep in mind that using Trace Bitmap sometimes results in an image that looks identical to the bitmap but with a larger file size. Consider this option only when the nature of the image is most suitable as a vector or when you want a special effect.

Figures 3.15 3.18 show several examples of bitmaps that have been converted to vectors by using different settings.

Figure 3.15. This image has large, smooth vector shapes that can be filled with any color.


Figure 3.16. Notice subtle differences in how the building windows are combined in the example on the right, which has a high color threshold.


Figure 3.17. Due to the relatively small threshold and minimum areas, this image looks posterized.


Figure 3.18. A large color threshold on the bottom left causes the sky to be banded.


     < Day Day Up > 


    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    Sams Teach Yourself Macromedia Flash 8 in 24 Hours
    ISBN: 0672327546
    EAN: 2147483647
    Year: 2006
    Pages: 235

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net