10. Several attributes of graphics.
Today I will talk about several attributes of graphics in drawimage.
Graphics is a big bag in GDI +. It can be used to draw lines, rectangles, or even various materials. Use different pen and brush. The specific method of use is all want to use the basis of GDI + students, I will not detail, specific can refer to msdn: http://msdn.microsoft.com/en-us/library/haxsc50a (vs.80). aspx. I mainly talk about two attributes that you don't pay much attention.
A. Graphics. compositingmode
This is an enumeration attribute. Two types of values can be obtained: sourceover and sourcecopy. This defines how graphics combines the current color and background. If sourcecopy is used, the color is not merged with the current background. If it is sourceover, the background color will be mixed with the current color,AlgorithmAs follows:
Display color = source color x alpha/255 + background color x (255-alpha)/255
The transparency of the new color is 255, that is, opacity. Let's take a look at the followingCode:
Private Int Compositecolor ( Int Color, Int Alpha, Int Backgroudcolor)
{
// Display color = source color x alpha/255 + background color x (255-alpha)/255
Return Color * Alpha / 255 + Backgroudcolor * ( 255 - Alpha) / 255 ;
}
Private Void Draw ( Object Sender, eventargs E)
{
This . Backcolor = Color. fromargb ( 255 , 255 , 255 );
Graphics g = This . Creategraphics ();
G. compositingmode = System. Drawing. drawing2d. compositingmode. sourceover;
G. fillrectangle ( New Solidbrush (color. fromargb ( 127 , 255 , 0 , 0 )), New Rectangle ( 0 , 0 , 200 , 200 ));
G. compositingmode = System. Drawing. drawing2d. compositingmode. sourcecopy;
G. fillrectangle ( New Solidbrush (color. fromargb ( 127 , 255 , 0 , 0 )), New Rectangle ( 200 , 0 , 200 , 200 ));
G. compositingmode = System. Drawing. drawing2d. compositingmode. sourcecopy;
G. fillrectangle ( New Solidbrush (color. fromargb (
255 ,
Compositecolor ( 255 , 127 , 255 ),
Compositecolor ( 0 , 127 , 255 ),
Compositecolor ( 0 , 127 , 255 ))
), New Rectangle ( 0 , 200 , 200 , 200 ));
G. Dispose ();
}
The 1st color blocks and the 2nd color blocks are both mixed and not mixed. If we want to achieve the mixed effect in a non-mixed manner, we should write the third color block. We can see the result clearly from the image below.
B. Graphics. compositingquality
Synthesis quality, a total of 5 types
| |
member name |
description |
| |
assumelinear |
assume the linear value. |
| |
default |
default quality. |
| |
gammacorrected |
Grayscale Correction is used. |
| |
highquality |
high quality and low speed combination. |
| |
highspeed |
high speed and low quality. |
| |
invalid |
invalid quality. |
This part is a bit of knowledge, and it is not clear in msdn. Some practical students use several other related attributes to explain the image quality in GDI +, such as NLP. I will explain some theoretical foundations of synthesis. It also needs to be distinguished from another attribute interpolationmode. The specific use of this attribute will be discussed in the next section, and the synthesis quality and interpolation are not the same thing.
According to the algorithm in the previous section, image synthesis is a floating point operation, which requires a large amount of computing. In addition, because image storage needs to be quantified at the end, the process of quantification may inevitably result in sawtooth. In order to smooth the sawtooth, a large amount of computation is required. Another problem is that if we have many layers of different transparent images that need to be synthesized, then each layer needs to be synthesized. In fact, this synthetic formula can be optimized. The compositingquality attribute is used by GDI + to solve these problems. In msdn, the higher the quality, the slower the speed, and the specific algorithm is unknown.
Highquality uses the Smoothing Technique to remove the Sawtooth appearance in the synthesis and synthesize the current gamma gray information. This calculation is the slowest, and the color is different from that of non-gammacorrected.
Gammacorrected combines the current gamma gray information without computation optimization.
The computation speed optimized by highspeed is slightly inferior. If it is not highly demanding, it cannot be seen.
The quality of assumelinear is slightly higher than that of default, and the speed is slightly slower. This algorithm assumes that the pixel changes in interpolation in synthesis are linear.
Default is the most basic calculation method.
Invalid is unknown, and I don't know. If you know it, you can tell me.
Among them, highquality/gammacorrected has the same effect, and the other four are the same. For more information, see.