GDI + image processing based on vc.net

Source: Internet
Author: User
Tags bmp image

We know that in the previous image processing, we often have to change the format of different image files and their data storage structure in different formats. The display of an image file is also based on the analysis of the file data structure, and then read the relevant image data to achieve. GDI + now provides image and bitmap classes that make it easy to work with images.

Overview

GDI + supports most popular image file formats, such as BMP, GIF, JPEG, TIFF, and PNG. These image files are described below, and then the attributes supported by the image and bitmap classes are described.

1. Introduction to Image File format

An image file is a computer disk file that depicts an image, and its file format is not less than dozens of. Only BMP, GIF, JPEG, TIFF, and PNG image file formats are described here.

BMP file Format

The BMP image File format is a standard image format that Microsoft sets for its Windows environment. A BMP bitmap for Windows is actually a bit array that corresponds to the display of pixels, and it has two types: one is called a GDI bitmap and the other is a DIB bitmap (device-independent Bitmap). The GDI bitmap contains a Windows data structure that is related to the Windows GDI module, which is device-related, so the bitmap is also known as the DDB bitmap (device-dependent Bitmap). When the user's program obtains bitmap data information, its bitmap display mode depends on the display card. Because of this device dependency of the GDI bitmap, the problem is likely to occur when the bitmap is transferred over the network to another PC.

DIB has many programming advantages over GDI bitmaps, such as its own color information, making palette management easier. And any machine running Windows can handle the DIB, and it usually has a suffix later. BMP file forms are saved on disk or as resources exist in the program's EXE or DLL file.

GIF file format

Graphics Interchange Format (Gif--graphics Interchange Format) was first established by CompuServe Company on June 15, 1987, which is mainly used for online transmission and storage of CompuServe Network Graphics data. GIF provides enough information and organizes the information well so that many different input can easily exchange images, it supports 24-bit color, is implemented by a palette of up to 256 colors, and the image is at most 64K x 64K pixels in size. GIF is characterized by LZW compression, multiple images, and interlaced screen drawing.

JPEG file format

The "Joint photographic Expert Group" JPEG (Joint Photographic Experts Group), established jointly by the International Organization for Standardization (ISO) and the Telegraph and Telephone Advisory Committee (CCITT), presented an ISO CD in March 1991 after five years of painstaking and meticulous work Draft recommendation 10,918th: "Digital compression coding for multi-grayscale still images" (usually referred to as JPEG standard). This is a compression standard suitable for color and monochrome multi-grayscale or continuous-tone still digital images. It includes lossless compression and lossy compression based on discrete cosine transform and Huffman coding in two parts. The former does not produce distortion, but the compression ratio is very small, the latter algorithm for image compression, although the information loss but the compression ratio can be very large. For example, when compressing 20~40 times, the human eye basically does not see the distortion.

JPEG image file is also a pixel format file format, but it is much more complex than BMP and other image files. Fortunately, GDI + 's image provides support for the JPEG file format so that we do not need to have too much knowledge of the JPEG format to handle images of that format.

TIFF file format

TIFF (Tagged image format file, logo image File format) was first introduced by Aldus Company in 1986, it can support any image from monochrome to 24-bit true color, and it is very easy to change and transform between different platforms. Unlike other image file formats, there is a tag information area in the TIFF file that defines the image data type, color, and compression method for the file store.

PNG file format

PNG (Portable Network Graphic, Portable Network image) file format is proposed and designed by Thomas Boutell, Tom Lane and other people, it is a kind of image file format designed to adapt to network data transfer, which replaces the simpler and The patent restricts the strict GIF image file format. Furthermore, this image file format can even replace the more complex TIFF image File format in some way. Its main features are: compression efficiency is usually higher than GIF, provide alpha channel control image transparency, support gamma correction mechanism to adjust the brightness of the image, and so on.

It is important to note that the PNG file format supports three main image types: True color images, grayscale images, and color-indexed data images. JPEG supports only the first two types of images, while GIF can compensate for the gray level of an image using a grayscale palette, but in principle it only supports a third type of image.

Mage and Bitmap Classes overview

The image class of GDI + encapsulates the ability to transfer, format, and simply handle BMP, GIF, JPEG, PNG, TIFF, WMF (Windows Metafile), and EMF (enhanced WMF) image files. The bitmap is an image class that inherits from the image class and encapsulates the common features of Windows bitmap operations. For example, Bitmap::setpixel and bitmap::getpixel are used to read and write pixels for bitmaps respectively, thus providing a possibility for the softening and sharpening of images.

3. DrawImage method

DrawImage is the core method of the Graphics class display image of GDI +, which has many overloaded functions. General overloaded functions commonly used are:
Program code:

Status DrawImage (image* Image, int x, int y);
Status DrawImage (image* Image, const rect& Rect);
Status DrawImage (image* Image, const point* destpoints, INT count);
Status DrawImage (image* Image, int x, int y, int srcx, int srcy,
int srcwidth, int srcheight, Unit srcunit); where, (x,y) is used to specify the position of the image display, which corresponds to the upper-left corner of the image. Rect is used to specify the rectangular area to be populated by the image, and destpoints and count are used to specify the number of vertices and vertices of a polygon, respectively. If Count is 3 o'clock, the polygon is a parallelogram and the other vertex is automatically given by the system. At this point, the data in the destpoints corresponds to the vertex coordinates in the upper-left, upper-right, and lower-left corners of the source image in turn. SRCX, Srcy, Srcwidth, and srcheight are used to specify the location and size of the source image to display, Srcunit to specify the units to use, and by default use Pageunitpixel, which is a unit of measure in pixels.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.