//画笔 var g: TGPGraphics; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); g.Clear(aclWhite); p:=TGPPen.Create(aclRed,5); {参数1颜色; 参数2是笔宽, 笔宽是可选, 默认 1} g.DrawLine(p,10,50,200,50); p.Free; g.Free; end;
//设置笔宽与颜色 var g: TGPGraphics; p: TGPPen; begin g := TGPGraphics.Create(Canvas.Handle); g.Clear(aclWhite); p:=TGPPen.Create(aclRed); {建立时应该不给参数是可以的, 但在测试中不行, 至少要给一个颜色} p.SetColor(aclBlue);{设置颜色} p.SetWidth(5);{设置笔宽} g.DrawLine(p,30,50,200,50); p.Free; g.Free; end;
//获取笔宽与颜色 var c:TGPColor; w:Single; procedure TForm1.FormPaint(Sender: TObject); var g:TGPGraphics; p:TGPPen; begin g:=TGPGraphics.Create(Canvas.Handle); g.Clear(aclwhite); p:=TGPPen.Create(MakeColor(200,80,0),10); g.DrawLine(p,30,50,200,50); p.GetColor(c);{获取颜色数值给C} w:=p.GetWidth;{获取笔宽数值给w} g.Free; p.Free; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(IntToHex(c,8));{显示颜色} ShowMessage(FloatToStr(w));{显示笔宽} end;