一、CompositingMode
獲取一個值,該值指定如何將合成圖像繪制到此 Graphics。復合模式確定從源映像的像素是覆蓋(SourceCopy)還是組合(SourceOver, 需要使用半透明、混合疊加效果時使用)使用背景像素。默認值為 SourceOver。
該屬性適用於 適用於.NET Framework 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1
不應使用CompositingMode屬性值為SourceCopy時TextRenderingHint屬性設置為ClearTypeGridFit。 可能會發生異常或圖像可能無法正確呈現。
二、CompositingQuality
獲取或設置繪制到此 Graphics 的合成圖像的呈現質量。組合的情況下質量決定將合成圖像的呈現質量級別。
CompositingQuality Enum
AssumeLinear | 4 | 假定線性值。 |
Default | 0 | 默認質量。 |
GammaCorrected | 3 | 使用灰度校正。 |
HighQuality | 2 | 高質量、低速度復合。 |
HighSpeed | 1 | 高速度、低質量。 |
Invalid | -1 | 無效質量。 |
三、InterpolationMode
The interpolation mode determines how intermediate values between two endpoints are calculated.
四、SmoothingMode
平滑模式指定直線、 曲線和已填充區域的邊緣是否使用平滑處理 (也稱為抗鋸齒)。 一個例外是路徑漸變畫筆不遵守平滑模式。 使用填充的區域PathGradientBrush呈現相同的方式 (別名) 而不考慮SmoothingMode屬性。
五、TextRenderingHint
The text rendering hint specifies whether text renders with antialiasing.
Note:
You should not use a CompositingMode property value of SourceCopy when the TextRenderingHint property is set to ClearTypeGridFit. An exception could occur or the image may not render correctly.
六、TextContrast
The gamma correction value used for rendering antialiased and ClearType text.
private void ChangeTextRenderingHintAndTextContrast(PaintEventArgs e) { // Retrieve the graphics object.
Graphics formGraphics = e.Graphics; // Declare a new font.
Font myFont = new Font(FontFamily.GenericSansSerif, 20, FontStyle.Regular); // Set the TextRenderingHint property.
formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel; // Draw the string.
formGraphics.DrawString("Hello World", myFont, Brushes.Firebrick, 20.0F, 20.0F); // Change the TextRenderingHint property.
formGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; // Draw the string again.
formGraphics.DrawString("Hello World", myFont, Brushes.Firebrick, 20.0F, 60.0F); // Set the text contrast to a high-contrast setting.
formGraphics.TextContrast = 0; // Draw the string.
formGraphics.DrawString("Hello World", myFont, Brushes.DodgerBlue, 20.0F, 100.0F); // Set the text contrast to a low-contrast setting.
formGraphics.TextContrast = 12; // Draw the string again.
formGraphics.DrawString("Hello World", myFont, Brushes.DodgerBlue, 20.0F, 140.0F); // Dispose of the font object.
myFont.Dispose(); }
參考資料
MSDN .NET 4.7.2, 18.9.20