雁过请留痕...
代码改变世界

【转】Graphics 关于呈现质量与合成模式

2015-01-14 15:34  xiashengwang  阅读(857)  评论(0编辑  收藏  举报

GDI+相关的作图,每种语言都有其自身的封装类,但本质上是一样的,下面这篇文章写的非常好,对于C#的Graphics类也是使用的,所以转载了,原文在这里:

http://www.cnblogs.com/del/archive/2009/12/22/1630120.html

相关内容有:


IGPGraphics.SmoothingMode;            { 绘图质量 }
IGPGraphics.InterpolationMode;        { 插补模式 }
IGPGraphics.CompositingMode;          { 前景色与背景色的合成混合模式 }
IGPGraphics.CompositingQuality;      { 图像合成质量 }
IGPGraphics.PixelOffsetMode;          { 像素的偏移模式 }

{ 文本的呈现质量要用 }
IGPGraphics.TextRenderingHint;        { 文本呈现模式 }
IGPGraphics.TextContrast;            { 文本灰度校正值(消除锯齿和 ClearType 文本的伽玛值校正) }


相关参数:
SmoothingMode { 对直线、曲线和已填充区域的边缘采用锯齿消除功能, 它不能控制路径渐变画笔 }
Invalid    // 一个无效模式  
Default    // 不消除锯齿, 等效于 HighSpeed、None
HighSpeed  // 不消除锯齿  
HighQuality // 消除锯齿, 等效于 AntiAlias
None        // 不消除锯齿  
AntiAlias  // 消除锯齿

InterpolationMode { 插补模式确定如何计算两个像素点之间的中间值 } Invalid            // 等效于 QualityMode 枚举的 Invalid 元素. Default            // 默认模式. Low                // 低质量插值法. High                // 高质量插值法. Bilinear            // 双线性插值法; 不进行预筛选; 将图像收缩为原始大小的 50% 以下时此模式不适用. Bicubic            // 双三次插值法; 不进行预筛选; 将图像收缩为原始大小的 25% 以下时此模式不适用. NearestNeighbor    // 最临近插值法. HighQualityBilinear // 高质量的双线性插值法; 执行预筛选以确保高质量的收缩. HighQualityBicubic  // 高质量的双三次插值法; 执行预筛选以确保高质量的收缩; 可产生质量最高的转换图像.
CompositingMode { 颜色合成模式 } SourceOver  // 与背景色混合; 该混合由透明度确定 SourceCopy  // 改写背景色
CompositingQuality { 图像合成时, 源像素与目标像素和合成方式 } Invalid        // 无效质量 Default        // 默认质量 HighSpeed      // 高速度、低质量 HighQuality    // 高质量、低速度复合 GammaCorrected // 使用灰度校正 AssumeLinear  // 假定线性值
PixelOffsetMode { 像素偏移模式 } Invalid    // 无效模式. Default    // 默认模式. HighSpeed  // 高速度、低质量呈现. HighQuality // 高质量、低速度呈现. None        // 没有任何像素偏移. Half        // 像素在水平和垂直距离上均偏移 -0.5 个单位, 以进行高速锯齿消除.

SmoothingMode 测试:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var   Graphics: IGPGraphics;   Pen: IGPPen;   Rect: TGPRectF;   i: Integer;
begin   Graphics := TGPGraphics.Create(Handle);   Pen := TGPPen.Create($FFB22222, 4);   Rect.Initialize(ClientWidth * 3/8, ClientHeight * 3/8, ClientWidth / 4, ClientHeight / 4);   for i := 0 to 4 do   begin     Graphics.SmoothingMode := TGPSmoothingMode(i);     Graphics.DrawEllipse(Pen, Rect);     Rect.Inflate(ClientWidth / 14, ClientHeight / 14);   end;
end;


InterpolationMode 测试:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var   Graphics: IGPGraphics;   Image: IGPImage;   Rect: TGPRectF;   i: Integer;
begin   Graphics := TGPGraphics.Create(Handle);   Image := TGPImage.Create('C:\GdiPlusImg\Grapes.jpg');   Rect.Initialize(10, 10, Image.Width * 0.5, Image.Height * 0.5);   for i := 0 to 7 do   begin     Graphics.InterpolationMode := TGPInterpolationMode(i);     Graphics.DrawImage(Image, Rect);     Rect.Offset(Rect.Width + 10, 0);     if Rect.X + Rect.Width > ClientWidth then     begin       Rect.X := 10;       Rect.Offset(0, Rect.Height + 10);     end;   end;
end;

procedure TForm1.FormResize(Sender: TObject);
begin   Repaint;
end;


CompositingMode 测试:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var   Graphics: IGPGraphics;   Brush: IGPLinearGradientBrush;   Rect: TGPRect;
begin   Graphics := TGPGraphics.Create(Handle);   Rect.Initialize(20, 20, 200, 60);   Brush := TGPLinearGradientBrush.Create(Rect, $FFA52A2A, $FFFFFF00, 0);   Graphics.CompositingMode := CompositingModeSourceOver; //默认模式   Graphics.FillRectangle(Brush, Rect);   Brush := TGPLinearGradientBrush.Create(Rect, $80A52A2A, $80FFFF00, 0);   Graphics.CompositingMode := CompositingModeSourceOver;   Rect.Offset(0, 20 + Rect.Height);   Graphics.FillRectangle(Brush, Rect);   Graphics.CompositingMode := CompositingModeSourceCopy;   Rect.Offset(0, 20 + Rect.Height);   Graphics.FillRectangle(Brush, Rect);
end;


CompositingQuality 测试:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var   Graphics: IGPGraphics;   Image: IGPImage;   Rect: TGPRectF;   Brush: IGPSolidBrush;   i: Integer;
begin   Graphics := TGPGraphics.Create(Handle);   Image := TGPImage.Create('C:\GdiPlusImg\Grapes.jpg');   Rect.Initialize(10, 10, Image.Width * 0.75, Image.Height * 0.75);   Brush := TGPSolidBrush.Create($800000FF);   for i := 0 to 4 do   begin     Graphics.CompositingQuality := TGPCompositingQuality(i);     Graphics.DrawImage(Image, Rect);     Graphics.FillRectangle(Brush, Rect);     Rect.Offset(Rect.Width + 10, 0);     if Rect.X + Rect.Width > ClientWidth then     begin       Rect.X := 10;       Rect.Offset(0, Rect.Height + 10);     end;   end;
end;

procedure TForm1.FormResize(Sender: TObject);
begin   Repaint;
end;


PixelOffsetMode 测试:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var   Graphics: IGPGraphics;   BrushBack: IGPHatchBrush;   Brush: IGPSolidBrush;   Rect: TGPRectF;   i: Integer;
begin   Graphics := TGPGraphics.Create(Handle);   BrushBack := TGPHatchBrush.Create(HatchStyleCross, $FFD0D0D0, $FFFFFFFF);   Graphics.FillRectangle(BrushBack, TGPRect.Create(ClientRect));   Rect.Initialize(0.34, 1, 5.1, 1.3);   Brush := TGPSolidBrush.Create($80FF0000);   Graphics.ScaleTransform(27.3, 17.3);   for i := 0 to 4 do   begin     Graphics.PixelOffsetMode := TGPPixelOffsetMode(i);     Graphics.FillRectangle(Brush, Rect);     Rect.Offset(0, Rect.Height + 1);   end;
end;

另外在补充一个万一老师的GDI+的学习文章列表地址,虽然是用Delphi写的,但是还是有参考意义:

http://www.cnblogs.com/del/category/113557.html