Languages - DevSource
DevSource: Microsoft Developer Resource DevSource Home Sponsored by Microsoft Home Add Ons Architecture Languages Techniques Using VS Forums
Home arrow Languages arrow Page 2 - GDI+ Image Handling in C#
GDI+ Image Handling in C#
By Rick Leinecker

Rate This Article: Add This Article To:

GDI+ Image Handling in C# - ' Image Types'
( Page 2 of 3 )

Image Types

The .NET framework supports many image types. But hey, most images on the Internet are Jpegs so we should use that format, right? Not necessarily. Different image types have different characteristics when they're rendered, and we need to discuss several of the most common formats. But first, take a look at the formats that are supported by the .NET framework in the following table.

Name Description
Bmp Bitmap image format (BMP).
Emf Enhanced Windows metafile image format (EMF).
Exif Exchangeable Image File (Exif) format.
Gif Graphics Interchange Format (GIF) image format.
Icon Windows icon image format.
Jpeg Joint Photographic Experts Group (JPEG) image format.
MemoryBmp Memory bitmap image format.
Png W3C Portable Network Graphics (PNG) image format.
Tiff Tag Image File Format (TIFF) image format.
Wmf Windows metafile (WMF) image format.
ADVERTISEMENT

Picture File Types: GIF, JPG, and PNG

There are three major types of image files that are commonly used on the Internet. While the .NET framework loads and saves ten different formats, the three that are used on the Internet are the ones that most people choose to use for standalone applications.

The three types that we'll talk about are GIF images, JPG images, and PNG images. GIF stands for Graphics Interchange Format. JPG (sometimes JPEG) stands for Joint Photographic Experts Group. PNG stands for Portable Network Graphics. Each of these image file formats offer different advantages and disadvantages; so, what we'll do right now is describe the image file formats and discuss the advantages and disadvantages of each. Deciding which image to use in which setting will be important.

GIF Image Files

The GIF format is a creation of CompuServe, and is used to store multiple bitmap images in a single file for exchange between platforms and systems. Many of these are high-quality images of people, landscapes, cars, and astrophotographs. The vast majority of GIF files contain 16 or 256 color quality images. Grayscale images such as those produced by scanners are also commonly stored using GIF, although monochromographics such as clip art and document images rarely are.

Although the bulk of GIF files are found in the Windows-based environment, GIF is not associated with any particular software application. GIF also is not created for any particular software application need, although most software applications that read and write graphical image data such as paint programs, scanner and video software and most image file display and conversion programs usually support GIF.

The biggest contrast between GIF and JPG is that GIF uses a lossless compression. The compression method used by GIF is LZW. That stands for Lempel, Ziv, and Welch, the three men who invented it. More correctly, Lempel and Ziv created the early version and Welch made modifications later on; but I digress. In any case, the compression method that GIF uses does not degrade the picture quality at all. Every time you save and load the same GIF image, it is recreated with 100 percent integrity. For this reason, if you have an image that must be crisp and clear, and reproduced with the absolute highest quality, GIF would be your choice.

One limitation of GIF in certain circumstances is that it is limited to 256 simultaneous colors. The 256 colors, though, are selected from a palette of millions of colors; but GIF files can only use 256 of those colors at a time. For most Web applications, there's a commonly accepted palette known as the browser-safe palette that many GIF images now use. If you use this browser-safe palette, your GIF images are almost guaranteed to have the best reproduction on systems all over the world. However, if you use some custom palette that is not easy to match on all systems, your image may not look the same and may suffer when it is displayed on another system. One big advantage of GIF files is that one GIF file can store multiple images, and the multiple images can be displayed in sequential order within a browser. These are called animated GIFs, and are very popular on the Web.

JPG Images

JPG refers to a standards organization, a method of file compression, and sometimes a file format. The JPG file interchange format is designed to allow files containing JPG and coded data streams to be exchanged between otherwise incompatible systems and applications. For instance, a Macintosh and an IBM compatible computer can share the same file. JPG files, unlike GIF files, use a compression method that degrades the image at least somewhat. This is called lossy compression: that is, there is a certain amount of loss every time the file is saved. For this reason, if you need an exact replication of the original image, JPG is not necessarily the choice you need to make.

One advantage of JPG, however, is that even with the image degradation you get, for photographic images, you really can't tell much of a difference. It does a great job in images of near photographic quality as opposed to those with crisp, sharp edges.

JPG images are also composed of 24-bit colors. Each pixel in a JPG image can be one of a different color selected from a palette of millions. This is far better than the limitation of 256 colors in a GIF palette. In this case, a JPG image can consist of millions and millions of simultaneous colors.

PNG Images

PNG is lossless as is the GIF format. PNG was developed to overcome the limitations of the GIF format. The first limitation it overcomes is the patented LZW compression algorithm that the GIF format uses. The LZW compression algorithm is not used making the PNG image format free of any royalties. It also overcomes the limitation of 256 simultaneous colors by offering up to 48-bit truecolor.

PNG is a good choice when you need crisp images that use more than 256 colors.



 
 
>>> More Languages Articles          >>> More By Rick Leinecker
 



Microsoft's Future: A Chat With Their CTO, Barry Briggs

Play Video >

All Videos >

Julia explores the Robotics Studio!

Read now >

Messages to Bill Gates!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.