Delphi GDI+学习记录(21): 颜色

//颜色透明度var
 g: TGPGraphics;
 sb: TGPSolidBrush;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 sb := TGPSolidBrush.Create(MakeColor(128,255,0,0)); {128表示半透明}
 g.FillRectangle(sb,10,10,100,100);
 sb.Free;
 g.Free;
end;

//使用 GDI+ 的颜色类型var
 g: TGPGraphics;
 sb: TGPSolidBrush;
 color: TGPColor; {其实颜色是 DWORD 类型的}
begin
 g := TGPGraphics.Create(Canvas.Handle);
 color := aclRed;
 sb := TGPSolidBrush.Create(color);
 g.FillRectangle(sb,10,10,100,100);
 sb.Free;
 g.Free;
end;

//颜色混合模式var
 g: TGPGraphics;
 p: TGPPen;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 p := TGPPen.Create(MakeColor(128,255,0,0),20);
 g.SetCompositingMode(CompositingModeSourceCopy); {改写背景色}
 g.DrawLine(p,11,11,111,111);
 g.SetCompositingMode(CompositingModeSourceOver); {混合背景色, 默认值}
 g.DrawLine(p,66,11,222,128);
 p.Free;
 g.Free;
end;

颜色混合模式:

Delphi 微软 说明
CompositingModeSourceCopy SourceCopy 指定在呈现颜色时,它改写背景色。
CompositingModeSourceOver SourceOver 指定在呈现颜色时,它与背景色混合。该混合由所呈现的颜色的 alpha 成分确定。
时间: 2024-11-03 22:02:44

Delphi GDI+学习记录(21): 颜色的相关文章

Delphi GDI+ 学习记录(28): 图像颜色的数据格式

//指定位图颜色var g,gbit: TGPGraphics; bit1,bit2: TGPBitmap; sb: TGPSolidBrush; begin //Self.Color := clWhite; g := TGPGraphics.Create(Canvas.Handle); sb := TGPSolidBrush.Create(MakeColor(255,0,0)); {画刷为红色} bit1 := TGPBitmap.Create(200, 32, PixelFormat32bp

Delphi GDI+ 学习记录(31): 图像颜色变换(TGPImageAttributes)

//正常显示图片, 没有变换uses GDIPAPI, GDIPOBJ; procedure TForm1.FormPaint(Sender: TObject); var g: TGPGraphics; img: TGPImage; begin g := TGPGraphics.Create(Canvas.Handle); img := TGPImage.Create('c:\temp\test.png'); {测试文件要存在} g.DrawImage(img, 0, 0, img.GetWid

Delphi GDI+ 学习记录(25): 变换

//比例变化 var g: TGPGraphics; p: TGPPen; rect: TGPRect; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(255,255,0,0),0); rect := MakeRect(10,10,100,100); g.DrawRectangle(p, rect); {原始} g.ScaleTransform(2, 0.5); {横向放大.纵向缩小} p.S

Delphi GDI+学习记录(19): 路径

//绘制与填充路径var g: TGPGraphics; path: TGPGraphicsPath; p: TGPPen; sb: TGPSolidBrush; begin g := TGPGraphics.Create(Canvas.Handle); p := TGPPen.Create(MakeColor(128,255,0,0),4); sb := TGPSolidBrush.Create(MakeColor(128,255,255,0)); path := TGPGraphicsPat

Delphi GDI+学习记录(11): 路径渐变画刷

//路径渐变画刷 var g: TGPGraphics; path: TGPGraphicsPath; pb: TGPPathGradientBrush; {声明渐变画刷} num: Integer; const colors: array[0..0] of TGPColor = (aclAqua); begin g := TGPGraphics.Create(Canvas.Handle); path := TGPGraphicsPath.Create; path.AddEllipse(0,0,

Delphi GDI+学习记录(10): 线性渐变画刷

//线性渐变画刷var g: TGPGraphics; lb: TGPLinearGradientBrush; rect: TGPRect; begin g := TGPGraphics.Create(Canvas.Handle); rect := MakeRect(11,11,222,111); lb := TGPLinearGradientBrush.Create(rect, aclBlue, aclGreen, LinearGradientModeHorizontal); g.FillEl

Delphi GDI+学习记录(9): 纹理画刷

//纹理画刷 var g: TGPGraphics; img: TGPImage; tb: TGPTextureBrush; begin g := TGPGraphics.Create(Canvas.Handle); img := TGPImage.Create('c:\temp\small.jpg'); tb := TGPTextureBrush.Create(img); g.FillEllipse(tb, 0, 0, Self.ClientWidth, Self.ClientHeight);

Delphi GDI+学习记录(8): 阴影画刷

//阴影画刷 var g: TGPGraphics; hb: TGPHatchBrush; begin g := TGPGraphics.Create(Canvas.Handle); hb := TGPHatchBrush.Create(HatchStyleHorizontal, aclRed, aclYellow); {参数1是阴影样式; 参数2是前景色; 参数3是背景色, 参数3可选, 默认黑色} g.FillEllipse(hb, 11, 11, 222, 111); hb.Free; g

Delphi GDI+学习记录(7): 实心画刷

//实心画刷 var g: TGPGraphics; sb: TGPSolidBrush; begin g := TGPGraphics.Create(Canvas.Handle); sb := TGPSolidBrush.Create(aclGreen); {参数是颜色} g.FillEllipse(sb, 11, 11, 222, 111); sb.Free; g.Free; end; //设置画刷颜色 var g: TGPGraphics; sb: TGPSolidBrush; begin