Seventh lesson: bitmap
I. Overview
In Windows, each screen is a graphic image, a smart Windows production system, facing a huge graphic programming task, established a library of colorful borders, buttons, icons, and fonts. Of course, through the Windows API, these functions can be called. The so-called Windows display screen and the numerous printers are actually "grating equipment". In the grating device, an image is composed of a plurality of scan lines and a separate pixel that can be accessed. Windows also supports non-grating equipment, such as a plotter, etc., I have no experience, I have nothing to talk, I want to go. The following is only discussed only by the display.
The core of the computer video system is memory. The memory contains data representing the display pattern, and these patterns are displayed on the monitor (display). Each mouse moves, a small amount of data in the memory changes. Then you will see the mouse pointer moves on the screen. Each time and each graphic operation affects video memory because GDI performs calculations and changes video memory in the corresponding manner. There is also a memory stored in the computer called bitmap memory. The important difference between bitmap memory and video memory is: The bitmap can not see, and video memory can be seen. That is to say, the image data placed in the bitmap is not reflected on the screen, while the image information stored in the video memory is reflected on the monitor. If the data that resides in bitmap memory is moved to video memory, the image will appear on the monitor. Take a desktop icon as an example, the icon is loaded into the memory from the disk (bitmap memory), and then the memory is moved to the appropriate address in the video memory so that the icon becomes the icon when the video memory is displayed through the video hardware. visible.
From the type of the image, there are two bitmaps in Windows, one called the device related bitmap (or the device-related bitmap), another name is not related to the device (or the device is unacceptable, or DIB). Unless specified, the bitmaps in W Indows are bitmaps related to the device. Some friends say a bitmap, it may think of the BMP image, but it is a bitmap that is not related to the device. In the field of programming, we often talk to bitmaps, generally not to refer to BMP images, but refers to the bitmap related to the device existing in the imagination. Another difference between the bitmap and the device-independent bitmap independent bitmap is to determine whether the bitmap has a handle. A bitmap with handles is a bitmap related to the device because it is one of the GDI objects. Common BMP images belong to a bitmap that is not related to the device. We generally don't call its bitmap, but called "BMP image" or called "DIB", which is an organization of data, not GDI drawing object. It is possible to understand the data saving mode of a standard format related to the device's bitmap data. For example, we can usually see files named BMP. This bitmap file places the organization information of the file on the file header, forms the same role in the form of some database files, and describes the structure of the file. The file head is tightly followed by the color data of the image. Due to the presence of this mechanism, a bitmap-independent bitmap-independent bitmap can be read and written between various devices.
There is only one format that is not related to the device, and the bitmap related to the device may. . . How many types of formats are there? Ghosts know! Fortunately, you don't have to know its format at all, just understand the memory block of the image data. It is like you have something to do with this, and you can do it with me.
The video system of the PC displays a matrix of a pixel (neatly arranged small light point). In a character-based environment, the video system contains a "hardware programming" shape, represents the location of the standard character and various draw characters (straight lines, corners, solid lines, etc.) and several symbols (smile, diamonds, " Shovel, etc.). Display a character by sending an ASCII code or ansi character code to the system. In Windows such a graphics display system, the computer and its software definition appears on the graphical shape on the screen. These shapes are represented by bitmap. The most important advantage of this method is that images and text can be displayed in different sizes, fonts, and methods. So, it is accurately, what is a bitmap? They are the collection of data elements, which determine what color is displayed on each screen position. In a monochrome (black and white) graphic image, each represents a screen pixel, 0 corresponds to black (no color), 1 corresponds to white (display color). Soon you will see that the bitmap can describe the color image. The number of digits of each pixel determines the number of different colors that can appear in a single bitmap. In addition to one monochrome video of each pixel, there are three other types: 1 color of each pixel generates, 8 bits produce 256 kinds of colors, 24-bit generate 16'777'216 color (supplement: I have already I saw 32-bit graphics cards). As shown in the following table: Color Supported by Windows
The total number of digits of each pixel is typically typical device 1 2 monochrome graphic 4 16 Standard Support VGA8 256 256 color VGA16 32'768 or 65'536 32K or 64K color SVGA24 16'7777'216 24-bit color set computer display system Performance determines the processing of Windows to color image. The display that is often seen now is SVGA (AGP has come out, mine is, but less information is less.). In theory, the SVGA system shows an amazing 16'777'216 color array. Systems that can be displayed 16'000'000 color ranges are often referred to as true colors. So what is the true meaning of "true color"? It stems from the imagination of a colorful display to display unlimited large-scale colors, the image will look completely "true". Real color display uses 24 points to determine the color of each pixel. 24 bits were divided into three groups, 8 digits per group, to represent red, green, blue color. (Reference: The color of the nature is combined by the three colors of red, green, and blue (RGB). It is called three-dimensional.)
Second, with the equipment is unlocked (DIB)
The so-called DIB refers to a bitmap that is not related to the device. DIB is not a Windows object, it does not have its own handle, actually a data file. As many data files, the beginning part of the DIB bitmap file has its inner data structure description section. Many books have made some diagrams to illustrate this problem, but I think it is better to witness the interior of the Dib file, it is better to see it. Now we are ready to see the BMP file is a 256 color bitmap, the file name is hua.bmp, which has been used in "VB Front" Demo Procedure No. 25.
Let us first check the general status of the file in the disk :D: / vbplay / vbplay25 /> DIR
Volume In Drive D Is Pro Volume Serial Number IS 268F-AB4B Directory Of D: / VBPlay / Vbplay25
.
D: / vbplay / vbplay25 /> debug hua.bmp-d 100 10000EAE: 0100 42 4D BE 78 01 00 00 00 00 00 36 04 00 28 00 bm.x ... 6 ... (. 0EAE: 0110 00 00 00 00 01 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 c4 0e-00 00 00 00 00 00 00 C4 0e 00 00 00 00 .............. 0EAE: 0130 00 00 00 00 00 00 00 80 80 80 00 00 00 ........ ........ 0EAE: 0140 80 00 00 80 80 00 00 00 00 ................
0EAE: 0150 00 00 80 00 80 00 40 80-80 00 40 00 00 FF 80 ... @ ... @@ .... 0eae: 0160 00 00 80 40 00 ff 00-40 00 00 40 80 00 ff ff ... @ .... @ .. @ .... 省 省 57 lines: 50 - 16-1 = 39 (16) = 57 (10) 0EAE: 0500 CC 00 AD E8 FD 00 78 AE-D3 00 1F 38 65 00 66 89 ... x ... 8e.f.0eae: 0510 F0 00 63 9B C3 00 79 AD-DA 00 08 13 73 00 0A 1c ..c ... y ..... s ... 0eae: 0520 A5 00 BB ED FD 00 83 C1-E5 00 2A 50 74 00 7C B3 ........ * Pt. .
0EAE: 0530 ED 00 56 82 BD 00 B3 66-B3 B3 6C B3 BD 8B C9 C9 ..V .... f..L ..... 0EAE: 0540 BD 50 21 60 6C 6C 44 44-B3 44 6C 86 44 66 44 D9.p! `Lldd.dl.dfd.0eae: 0550 44 B3 6C C9 87 7B B9 7B-44 BD 87 60 87 C9 6C AB DL. {D.. `.0eae : 0560 60 D6 6C AB AB 2A 88 55-88 7B 7B 7B 7B 3D 3D 3D `.l .. *. U. {{{=== 0EAE: 0570 C5 3D C5 24 7B 7B 7B 7B-B4 B9 7B B9 B5 C6 3d 7b. =. $ {{{{{.. {... = {(hereinafter all omitted) 0EAE: 1000 b3.-Q Note: If you use d: / vbplay / vbplay25 /> debug hua.bmp> > Temp.txt can save the results to the TEMP.TXT file and analyze research. But this is not seen after the order is given. At this time, you should type D 100 1000 this command and then press q to return to the DOS command line prompt. This content is obtained. For details, refer to the DOS Command Reference Manual. It is also possible to use PCTOOLS5.0.
The textual content of a plurality of bytes started by the first byte of the bitmap file is acquired by the above manner. Hereinafter, we analyze it. Before analysis, in order to grasp the structure of the DIB file as a whole, it is necessary to give the overall situation, as shown in the following table:
Composition of DIB files
Three major parties Description BitmapfileHeader 14 BitmapInfo BitmapInfoHeader 40 represented by red represents the minimum of 0, and the maximum 4 × 256. (In the 16-digit bitmap, there is no other part of this section) The part of the data part is greater than 0 (the specific size information record in the BitmapInfoHeader structure) can be seen that the DIB's file header is mainly It consists of two parts, ie BitmapfileHeader and BitmapInfo, and BitmapInfo is divided into BitmapInfoHeader and RGBQUAD two small parts. Let us an analysis. The first is the 14 bytes indicated by red, as follows
42 4D BE 78 01 00 00 00 00 36 04 00 00 This is the BitmapFileHeader section. The BitmapFileHeader structure is shown in the table:
BitmapfileHeader structure
Internal field data type Description bftype integer specifies the file type, must be bmbfsize long pointing to the size of the graph file, in bytes, BFREGERVED1 INTEGER reserves unused, must be set to 0BFReServed2 Integer, the BFOFFBITS long, from this structure to the byte of the bitmap data bit Offset This structure mainly records DIB file size and structural information. In many cases, these information can be calculated, so many people do not access data within this structure. Many people say that the BitmapFileHeader structure records information that is not used. Where bfoffBits illustrates the byte offset from this structure to the bitmap data bit. By accessing this field, we can know where the color data of this bitmap file is from where you start, or you can know how long the structure of the DIB file header. m_bmfileHeader.BFTYPE = 42 4D
This is an Integer integer data that this data must be 42 4D for the DIB file. So why is 42 4D, in fact, in the ASCII code table 42, the decimal 66 indicates that the uppercase B, 4D is a decimal 77 represents M, that is, the character 擝 M rickets? Telling Yuan Yu Yu 莸 莸 世 袷荄 袷荄 袷荄 文件 文件 文件 文件 文件 文件 文件 文件 文件 文件 文件
m_BmfileHeader.bfsize = be 78 01 00 = & H178BE = 96446 bytes
Describe the total length of the file. Note that the data on the right is high byte, that is, the address of the right byte is larger than the address value of the left byte, so be 78 01 00 = & H178BE. On the top, when using the Dir command to observe the file, we have seen the length of the file is 96446 bytes. Such as: Hua BMP 96, 446 04-04-99 12:06 hua.bmp
m_bmfileHeader.bfreserved1 = 00 00 (System Reserved, no data) m_bmfileHeader.bfreserved2 = 00 00 (System reserved, no data)
m_bmfileHeader.BfoffBits = 36 04 00 00 = & H00000436 = 1078 = 14 40 256 * 4
(From the beginning of the document, the length of the underlined data bit is 1078 bytes in the length of bytes. For the true color image, this data is often 36 00 00 00, ie 54. Description file header There is only a part of BitmapFileHeader (14 bytes) BitmapInfoHeader (40 bytes), that is, there is no RGBQUAD section. Why is there no rgbquad? Later, you will understand how it. Continue to see, continue)
The next step with this structure is tiered together, the composition is shown in the following table:
BitmapInfo structure (Table 2)
Structural field data Type Description BitmapInfoHeaderbmicolors RGBQUAD A RGBQUAD structure consisting of an array that is in this table, and there are two structures inside the structure, namely BitmapInfoHeader and RGBQUAD. Therefore, in a sense, the file header structure of the bitmap file can be made to three structures: BitmapFileHeader, BitmapInfoHeader and RGBQUAD. However, it must be recognized that the BitmapInfo structure is not independently exists from both of BitmapInfoHeader and RGBQUAD. The length of the BitmapInfoHeader structure is fixed, 40 bytes. The relevant instructions of the BitMapInfoHeader structure can be referred to as follows: BitmapInfoHeader structure (Table 3)
Structural field data Type Description Bisize Long Structure Length (40) BIWIDTH long Specifies the width of the bit map, specifies the height of the bitmap in pixels, specifies the level of the target device in pixels, BIPLANES INTEGER (must be 1 BiBITCOUNT INTEGER Bit (1, 4, 8, 16, 24, 32) BiCompression Long Specifies the compression type (Bi_RGB is not compressed) BisizeImage long specifies the size of the image, in bytes, Bixpelspermeter long Specify the device level Resolution, with the pixel of each meter as the unit Biypelspermeter long vertical resolution, the number of color indexes actually used in the color table in the color table, using O indicate that the number of colors indexes that are considered important to use BICLRIMPORTANT LONG. 0 means that all colors are important BitmapInfoHeader structure mainly records the size and color information of the data area. It must be understood that the BisizeImage field description is the size of the image, that is, the size of the data portion, not the size of the file. If we only read the data part of the bitmap into memory (and read the result portion into an array), you need to apply for a memory size in this size. In order to facilitate the control, I posted the demonstration data given here: 0EAE: 0100 28 00 bm.x ... 6 ... (. 0eae: 0110 00 00 69 01 00 00 06 01 -00 00 01 00 08 00 00 00 ..i ............. 0EAE: 0120 00 00 C4 0E 00 00 00 00 00 00 ... T. ........... 0eae: 0130 00 00 00 00 00 ................
The analysis is as follows:
Bisize = 28 00 00 00 = & H28 = 40 The length of this structure is 40 bytes. Always this data.
BiWidth = 69 01 00 00 = & H169 = 361 The width of the image (like the quality). Put this image into the PictureBox control and run the following command: text1.text = Picture1.scaleX (Picture1.Picture.Width, Vbhimetric, VBPixels) Results is: 360.9827. It can be seen that there is a little error in the calculation of VB. But if you use a plastic variable to read this data, then it is the same. Biheigh = 06 01 00 00 = & H106 = 262 The height of the image, please refer to BitWidth.
BIPLANES = 01 00 = & H1 = 1 must be 1.
BIBITCOUNT = 08 00 = & H8 = 8 Bits for each pixel. The bitmap file called Hua.BMP in the currently exemplified is a pixel in 8 bits, namely one byte. A 256 (2 8th) color bitmap can display the total number of colors defined in 256 colors, but this does not mean that any 256 color bitmap can only display the same 256 colors. 256 colors that can be displayed in a 256 color bitmap are specified in the RGBQUAD structure of the bitmap. 256 color range can be displayed by the color position map, can achieve the range allowed by the device (16-bit enhancement mode, 16 points 2, 24 times in the 24-bit true color mode) 24 times Party), but must be 256 colors. The color value described in the RGBQUAD structure is used to generate a palette. In this case, the data area is stored is an index value of these 256 colors, not the actual color. When a pixel is used to 1 digit, the number of RGBQUAD is 2, stored in black and white two colors, and the data area stores two index values; when using 4 points to represent a pixel At the time, the number of RGBQUADs is 16, and 16 colors are stored. The data area stores index number of 0 to 15; when the 8-bit color is stored in 256 colors, the data area stores index number of 0 to 255; When the pixel position exceeds or equal to 16 bits, the RGBQUAD structure portion does not exist, and the data area stores the actual color represented by a 16-bit or 24 bit. There is no palette in this case. One of the reasons I want to know, is we need to set up a toning palette?
Bicopression = 00 00 00 00 = & H0 = 0 Specify the compression type. Isn't it said that bi_rgb is not compressed? Let me check, how much Bi_RGB is? Come! Const bi_rgb & = 0 &, huh, this file is called no compression. Also: Const Bi_RLE4 & = 2 & and Const Bi_RLE8 & = 1 & Estimation is not used, want to compress, use JPG, why must I use BMP?
BisizeImage = 88 74 01 00 = & H17488 = 95368 The length of the image data (size). From the data relationship, it should be: the length of the image data file header = file length. Let us verify it, is it:
BisizeImage m_BmfileHeader.BfoffBits = 95368 1078 = 96446 = m_bmfileHeader.bfsize @@ ~ Sure enough!
Bixpelspermeter = C4 0e 00 00 = & HEC4 = 3780
Biypelspermeter = C4 0E 00 00 = & HEC4 = 3780 horizontal resolution and vertical resolution.
IbclRused = 00 00 00 00 = & H0 = 0
The number of indexes used in the color table (palette). Since it is 0, the explanation is ready. All is 256, more impossible. Don't use this data to determine the number of RGBQUAD arrays.
BICLRIMPORTANT = 00 00 00 = & H0 = 0
Specifies that the number of color indexes that is considered importance is specified, and all colors are important. Please choose 0 to choose 0, so you can help unity.
Different RGBQUADs with the BitmapInfoheader structure are an array, the length (RGBQUAD structure length × array element) can be a variety of situations, but not more than 256. The RGBQUAD structure is shown in Table:
RGBQUAD structure (Table 4)
Internal field data Type Description RgbBlue Byte Specifies how many rgbgreen byte of the color in color, specifies how many rgbred byte of the color of color, specifies how many RGBReserved byte retention, can be set to 00E: 0130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 80 80 00 00 00 ................ 0eae: 0140 80 00 00 80 80 00 80 00 ........ ........ 0EAE: 0150 00 00 80 00 80 00 00 FF 80 ... @ ... @@ .... 0eae: 0160 00 00 80 40 00 00 ff 00-40 00 00 40 80 00 ff ff ... @ .... @ .. @ .... 省 省 省 省 (still very long)
You probably I have already noticed, why do I use a red to indicate some 00? The reason is because they are idiots, only the place, which doesn't work, is the RGBquad structure in the RGBQUAD structure that Microsoft is reserved. There are three bytes per 00 and 00 and between the 00 and 00, of course, they represent the RGB color. Such color tables in color table should be equal to RGB (& H0, & H0, & H0), the color of the index number 1 should be equal to RGB (& H80, & H80, & H80), the color of the index number 2 is equal to RGB (& H0, & H0, & H80), push it to the color of the index number 255.
Okay! Now I have already talked fine enough, I can't be fine, I haven't played again. Then look at the data part.
0EAE: 0530 ED 00 56 82 BD 00 B3 66-B3 B3 6C B3 BD 8B C9 C9 ..V .... f..L ..... 0EAE: 0540 BD 50 21 60 6C 6C 44 44-B3 44 6C 86 44 66 44 D9 .p! `LLDD.dl.dfd.
I omitted below
We can see the data of the first pixel point is B3, ie 179, indicating that this color is comparable to the color of the index number 237 in the color table. So what color is the color? Worse, I will omitly omitted, not listed. Let's find a bar, see if there is anything. It seems that there is no. Forget it, just here. In fact, it is also a matter. But I still tell you, because you can find it yourself. The reason is: The line is stored in reverse sequence. That is, the first line in the pixel data portion of the bitmap file is actually the last row in the image. Dan said: Unless the Biheight section of the BitmapInfoHeader structure is set to a negative value, the starting point is in the lower left corner. However, most cases Biheight is not negative, so the starting point is generally in the lower left. But this is not to say that the starting point of the scan line is equal to the height of the image, the starting point is equal to 0, the end point is equal to the height. That is to say, the number of the scan line is arranged from 0, 1, 2, and 3 from the final line. Now, we have completed a comprehensive analysis of a bitmap file. If you still need to speak, then there are two points. The first point is about the true color bitmap. Already mentioned above, the true color bitmap is no color table. The data part of this figure is stored is the actual RGB color. So how do you know that there is no color table? It is actually very simple. It seems that the above has already been said, M_BmfileHeader.bfoffBits will be equal to & H36, ie 54. There is also BIBITCOTCOUNT that is greater than or equal to 16 bits.
The second point is an annoying regulation. We call a line of data in the bitmap called a scan line. Windows stipulates that each scan line must end with a 32-bit boundary. That is, the bit length of a scan line (bit calculation) must be divided by 32, or byte length must be divided by 4. In other words, if there is only 8 bits, then take a blank 24 to supplement, if only 48 digits, then take a blank 16 to supplement. We can confirm:
In the picture just now, we already know that the width of the image is 361 pixel points, the height is 262 pixel points. Then the total number of pixels in the data area is 361 × 262 = 94582. One byte in this example represents a pixel, but the number of bytes is not equal to 94582. As already seen, it is for BisizeImage = 95368. 786 bytes are still missing. This shows that some bits are given. A total of 262 lines, thus explaining that each line is added 786 ÷ 262 = 3 bytes, namely 24 bits. Why is each row to add 24 digits? It seems that there is only one possibility. That is, 32 bits are equal to 4 bytes, so 361 bytes will be removed after 4, and there must be 1, Windows has added 3 bytes of insufficient. Oh, 361 MOD 4 = 1 @@ ~
The VB code summary in calculating the number of bytes (scan line length) in the DIB line is summarized:
Imagewidth -> Bit map width (pixel) BMBITS -> Number of bit per pixel
Function GetLineWidth (BMBITS AS INTEGER, IMAGEWIDTH AS long) As long
GetLineWidth = ImageWidth
SELECT CASE BMBITS
Case 1
GetLineWidth = (GetLineWidth 7) / 8
Case 4
GetLineWidth = (GetLineWidth 1) / 2
Case 8
Case 16
GetLineWidth = getLineWidth * 2
Case 24
GetLineWidth = getLineWidth * 3
Case 32
GetLineWidth = getLineWidth * 4
Case elsegetLineWidth = 0 'Error
EXIT FUNCTION
End SELECT
IF (GetLineWidth and 3 &> 0 THEN _
GetLineWidth = (getLineWidth and & HFFFFFFFC) 4
END FUNCTION
The function related to the device-free bitmap is given below
Function explanation CreatedIBitMap creates a DibSECTION object with the device on a DIB basis (a new bitmap object, similar to the normal device related bitmap, but can also specify a buffer in memory To save bitmap data in the DIB format. The specific content has exceeded the scope of this lecture, the reader's own reference information) CREATEDIBCOLORTALBE acquires color table information for the Dibsection object. GetDibits is in the unrelated bitmap of the device such as data from a bitmap of the device. Very nice function. SetDibColortalbe Sets color table information for Dibsection. SetDibits sets images with data from a DIB with the device-related bitmap. SetDibitStodevice sets the data from DIB directly to a device. It can be used to pass data from DIB to the screen or printer. StretchDibits set the data from DIB to the device scene while telescopic image as needed. Some equipment supports direct data directly to the output device with this function. The GetDeviceCaps function can be used to determine if the specific support is supported. One of the common functions. Ok, everyone is a little rest, the next section we learn the bitmap related to the equipment.
Third, bitmap (DDB) related to equipment
The bitmap related to the device, relatively simple, relatively unlocked with the equipment, is relatively simple. Only simply because we don't have to learn its structure. Because, the format related to the device is always related to its equipment scenarios (by way, many books call the device scene "device context"). But the 2 color bitmap except. If you are sitting in front of the computer, don't think there is only one bitmap related to the device, it is not. The so-called device does not refer to a computer, memory, display cache, printer, and the like have its own bitmap data format. Do not give any guess to its structure. Have you seen me? Nothing? But do you feel that it is still very effective? We can communicate through Email, Internet. You will understand what I understand as a person, a distant friend can be, is it? It is ok to think about the bitmap related to the equipment. It does exist, just within a device of a computer (such as memory, printer). Of course, we cannot communicate with it through email, but to rely on functions, the scope includes creation, acquisition information, setting information, destruction, and more. It is used to find that this is also very good. It is also quite with the difficulty of sending me an e-mail ─ ─ fill in the required address, the required title and content, and then send it. Of course, here is to do for a function of calling the required parameters. If you really want to see it, I have a way, it is the secret of the family! Listen, you can take your computer to force your computer, please remember you have to force it, try it hard, then turn on the chassis to see if it is out, general success rate can reach 99%. But because there is a possible possibility of the 1% failure, I have to declare that if I don't see the consequences:)
It is always no longer forget to use the process of unrelated bitmaps with the device, ensuring compatibility of bitmaps and devices. You cannot select the bitmaps in a memory device scene to the printer device scene, there will be exceptions or errors. The device mentioned here is actually referring to the device scene. To create a device-related bitmap that is compatible with the specified device scene, you can use createBitMap or CreateCompaPaultBitmap. But the functionality of the two functions is different. My experience is that uses CreateBitMap when you create a Mask (Mask Bit) image, and create a color bitmap when using CreateCompAmPatibleBitmap. There are also several functions, such as CREATEDIBITMAP, which can create a bitmap with the device based on a DIB (device-free bitmap) basis. Anyway, you should notice that almost all API functions related to device-related bitmaps have an HDC parameter, sometimes it doesn't matter, but it should be clear that this is mainly given to ensure the compatibility of the equipment. Note Some information about the bitmap of the device is recorded in the device scene. As a GDI object, after the device-related bitmap is created, you need to select it into the device scene. This is exactly the same as a brush to the device scene. You can use the SelectObject function, just written on the parameter position to write the pen handle. The lower map handle can be. When you no longer use a bitmap you created by you, you should use the deleteObject function to release system resources. In order to delete it, you also need to select the original bitmap back to the device scene with the SelectObject function, so that you will be retracted back to the device scene, you can delete or resemble the status. This requires you to save the old (original) bitmap handle when you choose to choose a bitmap you create for your device. Anyway, this is exactly the same as the GDI object that manipulates the brush or painting. Similarly, you cannot select a bitmap to select two different device scenarios.
Creating and using a common trick of bitmaps is to create a DC or multiple DCs and the corresponding bitmap, and then in the background (the user can not see), various grating operations and processing are performed, and finally the image formed image is disposable. Send to the associated device scenario (the image in the associated device scene is automatically imaged to video memory, such as the memory represented by Picturebox and HDC. For details, please refer to the previous tutorial device Scene section) (common bitblt) to get the speed and Maximize the screen flashes (described later). This is mainly due to the slower speed of the function of the screen output image, and the processing process of the image is not necessary to see. In order to create several device scenarios, you need to use createCompatibleDC functions multiple times (this is also the easiest way), which allows you to get a device scenario with the specified device scene. Anyway, you should ensure that the HDC parameters used in the creation of the bitmap are consistent with the HDC parameters used in the creation device scenario. Don't forget to finally use DeleteDC to delete the device scene you created yourself. Before deleting the device scene, you should draw a bitmap to be selected from the device scene and destroy it. The above tips are called "double buffer" on a VC book. The aware is to divide the operation into the front desk and the background.
Next, give a function about the bitmap of the device, please don't welcome it.
About bitmap function
Function explains CreateBitmap Create a bitmap and selectively initializes bitmap data CreateBitMapIndirect to create a bitmap CreateCompablebitMap on a BitMap data structure to create a bitmap with the specified device scenario. GetBitMapbits Get bitmap Pixel data getBitmapdimensionEx acquires a bitmap loadBitmap to load a spicallywindex, which is a regular use of a split system bitmap loadImage from the resource file, which sets bitmaps in a data buffer setBitMapbitS. Image. Use GetDibits, it is better. SetBitMapDimensionEx Sets the size of the bitmap. Bitmap transfer function
The function is said to the Bitblt bit block transmission. Pass an image area to another image area. Must be grasped. Patblt pattern block transmission. An image area is filled according to the specified pattern (like a brush is represented). GetStRetChbltmode is used to determine the Windows delete line segment or pixel mode when retractable. Maskblt performs complex image transmission while making a mask (MASK) process PLGBLT parallelogram block transmission. Allow us to telescide, distort and place an image. This function I have used in Windows 95, which can always be successful. The function looks very good. When SetStretchBltmode is scaling, it is used to determine how Windows delete line segments or pixels. Stretchblt copies a bitmap from one device scene to another. Sources and target DCs must be compatible with each other. This function defines a target rectangle in the device scenario and defines an active image in the bitmap. The source rectangle is scaled as needed to match the size of the target rectangle. DIB does not exist in the device scene (Device Context). DIB must be translated into DDB before it is selected into the device scene or before it is drawn into the device scene. You can do this with the StretchDibits function. This tutorial provides a source code routine. Through it you can learn DDB to DIB, the process of conversion from DIB to DDB. The program name is vbplay46.vbp. In fact, the demo program in the source code resolution No. 46 is actually
In order to transfer the quality block transmission, you need to master the knowledge of graphic grating. Its content and bit operational operations given in the previous period are the same. Just need to be made is not one, two or four direct or other data, but a bitmap data. Bitmap data is also constituted by bytes, but the length is much longer. In order to use the raster calculation, you need to have a table to find and plan a raster solution. The following is the book of DAN, and it is also a table I like (detailed Chinese description format "is not as good as it):
SRCCopy Destination = SOURCE
SrcPaint Destination = Source Or Destination
Srcand Destination = Source and Destination
SRCINVERT DESTINATION = Source Xor Destination
Srcerase Destination = Source and (Not Destination) NotSrcopy Destination = Not Source
NotSrcerase Destination = (Not Source) And (Not Destination)
Mergecopy Destination = Source and Pattern
MergePaint Destination = (Not Source) Or Destination
PATCopy Destination = Pattern
PATPAINT DESTINATION = (Not Source) Or Pattern or Destination
Patinvert Destination = Pattern Xor Destination
Dstinvert Destination = Not Destination
Blackness destination = 0
Whiteness Destination = All Bits Set To 1
Unfortunately, there is a little important. Take a good worry, this teacher has a way:
& H220326 destination = (not Source) and points
Note: The destination refers to the target bitmap (in the previous DC in the Bitblt), Source is a source bitmap (in the latter DC in the Bitblt).
The following example is a function I have commonly used. It is used to implement a transparent replication bitmap. You can paste your use directly in your program. It summarizes the content given in this section.
Author (xing) sorted out of October 17, 1999
Function:
Transparent replication bitmap
Parameter table:
HDestDC -------- Long, target equipment scene
X, Y ------------ LONG, the point described in the upper left corner of the target rectangle in the target DC. Logical coordinates with target DC
NWIDTH, NHEIGHT - Long, wants to transfer the width and height of the image
HSRCDC --------- Long, source device scene. If the raster calculation is not specified, it should be set to 0
XSRC, YSRC ------ Long, the point that is described in the upper left corner position of the source DC. Logical coordinate of source DC
Transcolor ----- OLE_COLOR, transparent color
Sub TransBlt (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal TransColor As OLE_COLOR)
DIM DL AS Long
Dim Origcolor As Long
Dim Origmode As Long
DIM Savedc as long
DIM Maskdc As Long
DIM INVDC As Long
Dim Resultdc As Long
DIM HSAVEBMP AS Long
DIM HMASKBMP AS Long
DIM Hinvbmp as long
DIM HRESULTBMP AS Longdim HsavePrevbmp As Long
DIM HMASKPREVBMP AS Long
DIM Hinvprevbmp as Long
DIM HDESTPREVBMP AS Long
Savedc = CreateCompatibleDC (HDestDC)
Maskdc = CreateCompatibleDC (HDestDC)
INVDC = CREATECOMPALEDC (HDestDC)
Resultdc = CreateCompAMPATIBLEDC (HDestDC)
'Create a bitmap in accordance with the specified format
Hmaskbmp = CreateBitmap (NWIDTH, NHEIGHT, 1, 1, BYVAL 0 &)
Hinvbmp = CreateBitmap (NWIDTH, NHEIGHT, 1, 1, BYVAL 0 &)
'Creating a bitmap with equipment
HRESULTBMP = CREATECOMPATIBLEBITMAP (HDESTDC, NWIDTH, NHEIGHT)
HsaveBMP = CreateCompATIBLEBITMAP (HDestDC, NWIDTH, NHEIGHT)
HSAVEPREVBMP = SELECTOBJECT (Savedc, HsaveBMP)
HMASKPREVBMP = SELECTOBJECT (Maskdc, HmaskBMP)
Hinvprevbmp = selectObject (Invdc, Hinvbmp)
HDestPrevbmp = SelectObject (Resultdc, HRESULTBMP)
'Production Mask image
Origcolor = setbkcolor (hsrcdc, transcolor)
DL & = Bitblt (MaskDC, 0, 0, NWIDTH, NHEIGHT, HSRCDC, XSRC, YSRC, VBSRCCPY)
Transcolor = setbkcolor (hsrcdc, origcolor)
The image of 'Invdc will be opposite to Maskdc images
DL & = Bitblt (INVDC, 0, 0, NWIDTH, NHEIGHT, MASKDC, 0, 0, VBNOTSRCCOPY)
Image of 'resultdc will become image of written position
DL & = Bitblt (Resultdc, 0, 0, NWIDTH, NHEIGHT, HDESTDC, X, Y, VBSRCCopy)
In 'Resultdc, you need a new location where you need to change.
DL & = Bitblt (Resultdc, 0, 0, NWIDTH, NHEIGHT, MASKDC, 0, 0, VBSRCAN)
DL & = Bitblt (Savedc, 0, 0, Nwidth, NHeiGHT, HSRCDC, XSRC, YSRC, VBSRCPY)
The color that is not written in 'RESULTDC is black
DL & = Bitblt (Savedc, 0, 0, NWIDTH, NHEIGHT, INVDC, 0, 0, VBSRCAND)
'Putting two pictures
DL & = Bitblt (Resultdc, 0, 0, NWidth, NHEight, Savedc, 0, 0, VBSRCINVERT)
'Output after completion
DL & = Bitblt (HDestDC, X, Y, NWIDTH, NHEIGHT, RESULTDC, 0, 0, VBSRCCOPY)
SelectObject Savedc, HsavePrevbmpselectObject Resultdc, HDestPrevbmp
SelectObject Maskdc, HmaskPrevbmp
SelectObject Invdc, HinvpRevbmp
DeleteObject HsaveBMP
DeleteObject hmaskbmp
DeleteObject hinvbmp
DeleteObject HRESULTBMP
DeletedC Savedc
Deletedc Maskdc
Deletedc Invdc
Deletedc Resultdc
End Sub
API required by function
Private Declare Function BitBlt & Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal DWrop as long
Private Declare Function CreateCompatibleBitMap & Lib "GDI32" (Byval Nwidth As Long, BYVAL NHEIGHT AS Long)
Private Declare Function CreateCompatibleDC & LIB "GDI32" (Byval HDC As Long)
Private Declare Function DeleteObject & Lib "GDI32" (Byval Hobject As Long)
Private Declare Function SelectObject & Lib "GDI32" (Byval Hobject As Long)
Private Declare Function SetBkcolor & Lib "GDI32" (BYVAL CRCOLOR As Long)
Private Declare Function CreateBitmap & Lib "GDI32" (Byval NHEIGHT AS Long, Byval NPLANES As Long, Byval Nbit AS Long, LPBITS AS ANY)
Four, about imageio.dll
A few days ago, there are many friends to ask me how to save the images in the BMP image or picture box as JPG or GIF format files. I haven't answered it again. Because I have never found a satisfactory DLL (dynamic connection library). In the last 3 months, I have been learning VC, and it is also barely introduced. I found that many people in the VC world are using a dynamic connection library called ImageLoad.dll to complete these work. Unfortunately, this dynamic connection library is not good. Because its function uses a pointer (instead of handle). However, but, as long as the teacher is, you can use this dynamic connection library. The teacher wrote a dynamic connection library called Imageio.dll, written in VC. This connection library is fully compiled by VB, and the natural parameters are fully considered VB users. The connection library can appropriately change the handle you transferred in VB into a pointer and call the imageload.dll this dynamic connection library, and then return the processing results to the VB user in a VB acceptable manner. Another point is that the function of imageload.dll is relatively low, and it is not ascertain. To this end, I wrote some code in Imageio.dll, making it more convenient and more reliable. However, there have also been a thing that follows me sad. The first is that the function cannot read some of the partial GIF format files (some can be read, but not animation, only one static picture); the other is unable to store GIF format, the last point is quirky, when the image is not When you are equal to 24, the bitmap file cannot store the JPG format. The connection library can manipulate 6 in format files, with BMP, GIF, JPG, PCX, TGA, TIF. I haven't considered TGA and TIF, because I feel this imageio.dll after some problems in GIF, and TGA and TIF are not common files, and they are not tested. So, is it because I still don't understand VC? No, not I write wrong code, but the demo program provided by the dynamic connection library can also solve the problems I have encountered. According to the book processing, a JPG library code requires one person to use half a year. I can't spend half a year to write a library file. In fact, I have one in my hand, but I am too lazy to use it.
I consider, what can you do with imageio.dll? Want to write an image processing software? If you think so, then I suggest you don't use it, if you really want to edit an image processing software, it is best Still writing a complete DLL file from your head. I think it is a company that is a famous image processing software. And I suggest you use VB to write this software, not suitable. I think, for the vast majority of VB, demand for JPG is undoubtedly compressed some image files to save disk space. For example, you need to write a personnel file management system, saving the photos after scanning into JGP files. Then I think, you use this imageio.dll file, it is very good. I have downloaded a DLL file on the network, but the compression quality is poor, but imageload.dll is well done.
You can find a Test.vbp file in this tutorial package, which is written on this imageio.dll. The technical documentation about imageio.dll is now given, welcome to mention some valuable comments:
Imageio.dll
This dynamic connection library is to solve the VB user cannot be written using the imageLoad.dll dynamic connection library file. It can be used as a bridge that allows VB users to use imageload.dll. But it is not a simple conversion to ImageLoad.dll, but adds many code to make it easier and convenient. It helps users work to complete data from multiple image files such as BMP, GIF, JPG. Producer :xing
Programming environment :vc6.0
Date :1999, 12, 20
Constant:
1: File format
Const imagetype_none = 0 'Unknown format
Const imagetype_bmp = 1 'BMP file format
Const imagetype_gif = 2 'GIF file format
Const imagetype_pcx = 3 'PCX file format
Const imagetype_tga = 4 'TGA file format
Const imagetype_jpg = 5 'JPG file format
Const imagetype_tif = 6 'TIF file format
Const imagetype_firsttype = iMagType_bmp 'First File Format (BMP) = 1
Const imagetype_lasttype = imagetype_tif 'Last File Format (TIF) = 6
Function:
GetImageType
VB:
Private Declare Function GetImageType lib "Imageio.dll" (LPSFILENAME AS STRING) AS Long
VC:
__API INT GetImageType (LPTSTSTR & PSZFileName);
Speaking:
Get graphics file types
Return value:
File type 0-6,0 indicates an error or unknown file type
Parameters:
LPSFILENAME STRING file name
ImageLoad
VB:
Declare function imageload lib "imageio.dll" (LPSFILENAME AS STRING, BYVAL HDC As Long, Byval NX As long, Byval NY As long) AS Long
VC:
_API HGlobal ImageLoad (LPTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTSTER, INT NX, INT NY);
Description:
Load an image file and output to the specified DC if necessary
Return:
Returns a pointer to a buffer with image file data. No matter where you open any file, the data loaded into the buffer is already converted to a DIB format, that is, the same as the BMP file. When not using this buffer, you should release the KillImage function provided by the API function GlobalFree or this dynamic connection library.
Parameters:
KillImage:
VB:
Declare Function Killimage Lib "Imageio.dll" (Byval HDIB AS Long) As long
VC:
__API HGlobal KillImage (Hglobal HDIB);
Description:
This function is exactly the same as the API function GlobalFree, of course, can, of course, can be used to use GlobalFree. The VC code is as follows:
Hglobal CimageioApp :: KillImage (Hglobal HDIB)
{Return (HDIB));} Note: Returns HDIB if you returned to 0, otherwise returns HDIB.
ImageDraw: VB: Declare Function ImageDraw Lib "ImageIo.dll" (ByVal hDib As Long, ByVal hDC As Long, ByVal nX As Long, ByVal nY As Long) As LongVC: __API BOOL ImageDraw (HGLOBAL hDib, HDC hDC, int nX, INT NY); Description: Output image to the specified DC. Return value: successfully returns 1, otherwise it returns 0. Parameters: HDIB a pointer to the buffer. DIB bitmap data is installed in this buffer. You can get it with the loadImage function. You can also create it yourself. The HDC needs to draw an image of the device's normal scenario NX, the coordinates of the top left corner of the image in the NY device scene.
GetInfo: VB: Declare Function GetInfo Lib "ImageIo.dll" (ByVal hDib As Long, BIH As BITMAPINFOHEADER) As LongVC: __API BOOL GetInfo (HGLOBAL hDib, BITMAPINFOHEADER & BIH); Description: GetImageInfo as wanted by the function name, but There are some conflicts in VC, and GetInfo has been used. This function is used to get BitMapInfoHeader structure information in the DIB file. Return value: successfully returns 1, failed to return 0.
Parameters: HDIB a pointer to the buffer. DIB bitmap data is installed in this buffer. BiH a BitmapInfoHeader structure that is ready to load information. There is no need to set its Bisize member variable before passing.
__API Bool ImageSave (lptstr & pszfilename, hglobal hdib, int ntype, int nquality)
Only for BMP, JPG, TGA
Five, charts and pointers
The chart is a small image, the common additional name of the chart file is ICO. Its special ability is to not only allow any pixels to use some bitmap colors, but also allow them to use screens or reverse screen colors. The chart in Windows3.x is usually 32 × 32 pixels, but in Windows95 (98) and NT4.0, support for 16 × 16 and 64 × 64 pixel icons is very common. The icon actually contains two independent bitmaps. The first bitmap may be monochrome or colored, which contains an image to be combined with the display screen image. This merge is achieved by different or (xor). We refer to it as a xor bitmap, which contains a mask. The mask will be and the screen image is first and the screen image is followed by the XOR bitmap. Then the XOR bitmap and the screen for xor.
The mouse pointer is completely consistent with the interior structure and the chart, but it is more than a magazine, that is, the accurate coordinate point representative of the pointer position. The additional name of the file is usually CUR. Most of the functions that can operate on the icon can also be paired (mouse) pointers.
A handle will be generated after the icon is loaded into the memory. However, it should be noted that the chart does not belong to the GDI object, but belongs to the User object. So it is possible to share chart resources between applications.
The API function about icons and pointers is given below
The function is clear, the CopyCursor replication pointer, and the chart is replicated using the Copyiconcopyicon. CreateCursor create a pointer CreateIcon create a chart CreateIconIndirect create an icon DestroyCursor pointer on the basis of a clear structure ICONINFO on DestroyIcon clear chart DrawIcon draw an icon DrawIconEx to the specified device icon depicting scenes ExtractIcon loaded with additional options icon ExtractAssociatedIcon from an executable file or DLL Loading an icon in the specified file or an icon GeticonInfo to obtain information on the icon loadCursor loaded from a resource file or loads an intrinsic system pointer. LoadCursorFromFile By reading a standard pointer (.cur) or animation pointer (.ani) to load the chart from a resource file or load a secluded system icon. Six, color range
RGB We already know that the color on the IBM compatible video system is embodied by RGB. Each color in the RGB three colors contains the value of red, green, and blue components in colors. The value of these three parts is combined to determine the color displayed on the screen. RGB is a common color space, red, green, and blue are considered to be basic colors, and cannot be further decomposed. The color system can be divided into two types, addition color systems and subtraction color systems. The addition color system, such as the colors in the RGB system, can create a new color by adding colors to black. The more colors added, the more the colors will become white. Sufficient main colors can create pure white, and the lack of all major colors can only be pure black.
A RGB is made of four bytes. It seems that the remaining bytes other than the red, green, and blue three bytes are redundant, which is not. A color from an API drawing function is not just three bytes of red, green, blue color value, and also uses the fourth byte (highest byte). This byte contains a flag value. The minimum byte arranged in sequence contains red values, followed by green and blue, while the last bit byte contains a flag. This flag is used to indicate whether a high-frequency pulse color is referenced, or a palette matches color, or an obvious palette index. The value of this byte determines how the three low bytes of order arrangements have selected a color. When you want to specify a pen or brush in the API function of these objects, you can set the high byte to one of the three values in the following table.
High-character values result & H00 After the object is drawn, the Windows high-frequency pulsation 20 reserved color, this is called RGB color reference. (Common Situation) & H01 The lowest byte is not a red value, but refers to the number or index value of a palette item, so Windows uses two bytes in the color, the middle of the palette (byte 1 And 2, the original green and blue bytes) should be kept & h00, which is called a palette index reference. & H02 Windows positioning with red, green, and blue decisions the color most matching palette items specified in the three sequences of the low bytes. This is called a palette RGB reference. Therefore, it is tightly that a RGB value is composed in the following ways.
DIM RGBCOLOR AS Long
RGBCOLOR = RedValue (GreenValue * 256) (BlueValue * 65536) _ (Flagvalue * 16777216)
Use of this technology, please refer to the procedure Palette.vbp included in this tutorial.
CMY has several variants of RGB color intervals in the computer area. One is called CMY color range. It refers to blue green, purple and yellow. When the printer and camera rendered color through the ink emulsion, the subtractive color system is employed. It is used by most hard copy devices that precipitate color pigment into white paper, such as laser printers and inkjet printers. These three colors are absorbed with their own light color when they are reality. Blue-green absorbed red, purple absorption green, yellow absorption blue. For example, it can increase the amount of yellow ink, and the amount of blue in the image is reduced. The conversion between the RGB mode and the CMY mode is very simple. In order to calculate blue green, subtract red values in RGB from 255; for purple, subtract green values in RGB from 255; as for yellow, oh! You have guess, that is, subtract the blue value in the RGB from 255. For example, the CMY values of RGB (240, 12, 135) are 15, 243, and 120, respectively. However, this color range is probably not what we are interested in, of course, is also interested. But the color range given below is more attracted to us, and at least it is me.
HSV (color, concentration, brightness) HSV is one of a number of color systems. If you open the Color dialog family of General Dialogs, you will find that in addition to the RGB mediator, there is a similar but its value is quirky mediation. Many 3D animation software and image processing software are also widely used in this HSV color space. Its basic principle is to change the color attribute value to create a new color instead of using the color itself mixed. Color color, such as red, orange, blue, etc. Saturation (also known as concentration) indicates a white amount indicative of tone: full saturation and hue do not include white, showing solid color. The part contains the color of the color according to the mixed white, and the color is displayed. For example, 50% of the red tones of the saturation are shown as pink. The value (also known as brightness) is the color of the color itself, that is, the light it emits. High saturation tones are very bright, while low saturation tones are very dark.
HSV and painters and other colors systems used by artists who create colors, black and grays to creating colors, shading, and tones are very similar. Color is solid color, which combines white full saturation color, and the shading is a combination of black full saturation color. If you use these two colors, the saturation of the HSV is white, the value is black, and the hue is added to two colors after black and white. More detailed situation is no longer here, it is also difficult, not common, and later make a program in the site.
Seven, about the basics of palette
Regarding the palette, very little book talks deeply, the Dan's book is so little bit, less is very poor, even a palette's API is not given. In order to understand it, I also paid a lot of time. Of course, give you explanations now. Summary of knowledge from all corners here, I want to see friends who are satisfactory, I can see, I don't have any access. .
The image displayed on the brief is likely to require a large number of different colors. I can imagine: Photos of Green Rolling Irish Hills will need more different colors than the picture of Mars. If the user wants to display these two images, it will encounter a real problem. Even if you don't limit your reality, you can't even use 256 colors, users can have sufficient thick levels and provide two images. Fortunately, if only one picture is displayed at a time, the user can ask Windows to exchange colors, so that each image can activate its 256 color selection - its own color palette. So, what is a palette? It is a Windows object, but appropriate, if you imagine it as a specific group of structures, it will help. Remember the RECT structure, if Dim MyRect (0 to 255) AS Rect, we define an RECT structure array. Of course, all idiots know that the palette is not Rect. The palette structure is complicated than RECT. First, the palette is a structure called LogPalette. Made as follows:
Type Logpalette Palversion AS Integer PalNumentries As Integer Palpalent (1) AS PALETTEENTRY
End Type
Palversion refers to the version number of Windows, a value 300 represents Windows 3.0 or 3.1, but keep in mind that this value is still used in Windows 9x, ie 300. The number of the second parameter value palette login. That is, it refers to the number of elements of the third parameter Palpalentry. This example is obviously 1! So what is the following?
TYPELETTE PALVERSION AS INTEGER PALNUMENTRIES AS INTEGER PALPALENTRY (255) AS PALETTEENTRY END TYPE is of course 256. But this is not necessarily, it is not less than 255. For example, in the 4-bit mode, it should be 16, even if you declare Palpalent (255), when you create a palette, the function uses only the array elements of the previous 0 to 15.
Next, as you have seen, the third parameter is an array of structures. Of course not Rect 喽, but Paletteentry. Its content is as follows:
TYPE PALETTEENTRY PERED As Byte Pegreen As Byte Peblue As Byte Peflags as Byte End Type
RED, Green, Blue, don't have to say it? What is the last peflags? It is a value that includes one or more color flags that describe the palette item type. Some logos are shown as follows:
The logo value indicates that PC_EXPLICIT & H2 creates a palette entry that specifies an index in the system palette and not color. There are programs that display the contents of the system palette. PC_NOCOLLAPSE & H4 creates a palette entry that is not intended to be unused in the system palette, even if the color entry already exists. Used to ensure the uniqueness of the color palette when the two strips are shining onto the same color. PC_RESERVED & H1 Creates a designer palette entry for an application. When the PC_RESERVED entry is added to the system palette, it is not shaped onto the colors in other logical palettes, even if these colors match. Use the program that performs a palette animation. On the 8-bit display, the color of a pixel is determined by viewing its own 8-bit pixel value in a color table. A palette contains a set of 24-bit RGB color values (Pred, Pegreen, Peblue). The number of colors in a palette is up to 256 (from 0 to 255). Each display memory pixel option contains a value from 0 to 255. This pixel specifies which palette item is used to color this pixel. To change the color of a pixel, the user has two options: one, can change the color index value of this pixel; two, change the color value (RGB value, 24 bits) on the palette login. In the latter case, this change allows all pixels of all references to the color of the palette to simultaneously cause color changes.
However, you should be clear, initialize a logpaalette variable, can't say it is a palette. Because the palette is a member of the GDI object, just like a brush, a GDI object such as a brush, it must be created through a specific function. After you create, we can get a palette handle, then the handle is the true palette.
The image displayed by each user can take its own color palette. In addition, each active window can operate the palette according to its own purpose. However, remember, applied to full screen, with 256 colors, which is not for each window or application. For these, you have to use the Windows Pattern Manager to manage. Windows Patterboard Manager decides which window has a palette control in a given time. Windows in the front desk often have priority. If this window does not use a palette, the priority is passed to Z-direction (Z-Order, I have heard it? It is perpendicular to the screen. Because we often expressed the screen coordinates with x and y. And the three-dimensional coordinates are using X , Y, Z is expressed. The z-axis referred to herein is not the z-axis in the three-dimensional coordinates, but is just named by a metaphor of an image, refers to the next window of the desktop window. Once you have the highest priority window to recognize your palette as a front palette, the other window will be notified as a background palette in turn, which is notified by the Palette Manager. In general, the palette manager is automatic.
I just said a word "recognized". So, what is "recognizing a palette"? The image displayed by each user can bring its own palette (several palette can be placed simultaneously). The palette stored in memory is called a logical palette. In the user display system, the palette determines which color actually appears on the screen, this palette is called the system palette or hardware palette (concentrate! The system palette is hardware layer) only one The hardware palette and the palette manager retains a copy palette there. When an application activates its own color, it must select the logical palette in Device Context and recognize it. This means that the application must require a palette manager to load its logical palette to the system (hardware) palette. Therefore, the so-called "recognition" is actually a "worship", or "there are more care": "Please take care, use my palette. Because only this, the application can display the color that meets yourself.
Since the size of the palette changes, the palette manager will not be stupid to copy a block of 256 color elements from the logical palette to the hardware palette. Instead, this palette manager is only loaded in so many colors found in each logical palette. The system palette can accommodate multiple logical palettes, as long as the total color is not more than 256. Windows is static color (for painting buttons, borders, text, charts, etc., called system reserved color. There are several types of palette logins that can be obtained with GetSystemColor functions. Therefore, only 236 variable color locations remain. But this does not mean that a palette will only include 236 colors it needs to support its bitmap. Transforming 8-bit image palettes into a WINDOWS body palette is wise. The Windows body palette includes 20 reserved colors, especially when the user is planning to draw a palette, otherwise the color cannot be used. The Palette.vbp program comes with this tutorial If you run in 16-bit or 24-bit mode, only these 20 colors will only be displayed. If the user is willing, you can use the system static color to extend the defined color range to 256. GDI provides special functions for this purpose. But this will interfere with the basic commands of other actors because it will dynamically change the appearance of the active program. Therefore, unless your program exclusively on the entire screen (such as some games, this is not displayed simultaneously with other window programs), otherwise this approach should not be taken. Colors in a logical palette generally do not occupy the same position in the logical palette in the system palette. This is because when a palette is recognized, the palette manager establishes a cross-reference table, also called a palette image (Palette mapping), as it loads a logical palette to the system palette. This table is used for GDI drawing function to translate pixels from logical palette to the system palette index. It is very understandable. It can imagine it as a two column table, and the color index value of the logical palette is filled in the left column, and the index value of the system palette is filled in the right column. Just like an English dictionary corresponds to a Chinese word. Remember, the so-called image in the computer refers to this situation. For example, a message image, which calls a corresponding message processing function for various message values. Then come. As explained earlier, the color of a pixel is determined by viewing its value in the color table. In the case of device-related bitmaps and DIBs (device-free bitmaps), this is the most universal form of 256 color bitmap files, and the byte of the unit image size data is included in the color table of the file. value. When the GDI shifts the image from the file to the screen, it is to say that from one device-related bitmap to another, it changes with a palette image when it is a bitmap or DDB (device-related bitmap) that depends on the device. The pixel value makes it reference the currently correct color in the system palette. The palette image created for a logical palette is called a foreground image.
If you do not get all the palette logins from the active window, the remaining position is filled in the color from the non-active window, until or all position occupies, or there is no other window to identify your own palette position. . If the front desk requires all 236 free color positions, all non-active windows must be dominated by the front desk. The palette manager can also perform this service automatically, which is achieved by putting the color image in the non-active window to the most matching color in the currently identified palette. This is the so-called background image. This sometimes creates interesting but for most people. For example, the most color = does not match, and other colors = do not match. In addition, you need to remember that when the focus is replaced from a palette-based application to another, the entire identification process is repeated once.