Рисующее приложение в версии .NET, страница 15

¨  Exchangeable Image File (EXIF). EXIF is a file format used for photographs captured by digital cameras. An EXIF file contains an image that is compressed according to the JPEG specification. An EXIF file also contains information about the photograph (date taken, shutter speed, exposure time, and so on) and information about the camera (manufacturer, model, and so on).

¨  Portable Network Graphics (PNG). The PNG format retains many of the advantages of the GIF format but also provides capabilities beyond those of GIF. Like GIF files, PNG files are compressed with no loss of information. PNG files can store colors with 8, 24, or 48 bits per pixel and grayscales with 1, 2, 4, 8, or 16 bits per pixel. In contrast, GIF files can use only 1, 2, 4, or 8 bits per pixel. PNG improves on GIF in its ability to progressively display an image; that is, to display better and better approximations of the image as it arrives over a network connection. PNG files can contain gamma correction and color correction information so that the images can be accurately rendered on a variety of display devices.

¨  Tagged Image File Format (TIFF). TIFF is a flexible and extendable format that is supported by a wide variety of platforms and image-processing applications. TIFF files can store images with an arbitrary number of bits per pixel and can use a variety of compression algorithms. Several images can be stored in a single, multiplepage TIFF file. Information related to the image, such as scanner make, host computer, type of compression, orientation, samples per pixel, and so on can be stored in the file and arranged through the use of tags.

GDI+ provides the Bitmap class for working with bitmap images. The Bitmap class derives from the Image class but provides additional methods for loading saving, and manipulating bitmap images. To load a bitmap from a file and display that bitmap on the screen, you use a Bitmap object and a Graphics object. The Bitmap class supports several file formats, including BMP, GIF, JPEG, PNG, and TIFF. To load and display a bitmap:

1. Create a Bitmap object. When you create the Bitmap object, pass the name of the image file to the Bitmap constructor.

2. After you have created a Bitmap object, pass that Bitmap object to the DrawImage method of a Graphics object.

The following example creates a Bitmap object from a JPEG file located in the startup folder of the application and then draws the bitmap with its upper-left corner at (60, 10).

string fileName = Application.StartupPath + @"\Bitmap.jpg";

Bitmap fileImage = new Bitmap (fileName);

e.Graphics.DrawImage (fileImage, 60, 10);

The Graphics class in GDI+ provides several DrawImage methods, some of which have source and destination rectangle parameters that you can use to crop and scale images. One of the DrawImage methods receives a Bitmap object and uses a Rectangle object to specify the size of the drawn image. The rectangle specifies the destination for the drawing operation; that is, it specifies the rectangle in which to draw the image. If the size of the destination rectangle is different from the size of the original image, the image is scaled to fit the destination rectangle. The following example draws an image full scale and then draws the image with scaled coordinates.

Bitmap bitmap = new Bitmap ("../../avisse09.jpg");

g.DrawImage (bitmap, 0, 0); // Draw the original image

float  // Actual Size

cx = bitmap.Size.Width  * g.DpiX / bitmap.HorizontalResolution,

cy = bitmap.Size.Height * g.DpiY / bitmap.VerticalResolution;

Rectangle r = new Rectangle (0, (int)cy, (int)(cx/2), (int)(cy/2));

g.DrawImage (bitmap, r); // Draw half the size