现在要做一个类似大头贴的软件,拍完照片后,可以用鼠标来签名,功能实现了,但签字的效果一直不理想,原来用的Canvas
image.Canvas.MoveTo(prex, prey);
image.Canvas.LineTo(x, y);
写出来的字,很生硬,有棱角,不圆滑后来用的GdiPlus
graphics := TGPGraphics.Create(self.Canvas.Handle);
pen:= TGPPen.Create(MakeColor(255, color_r, color_g, color_b), nowPenWidth);
graphics.SetSmoothingMode(999) ;
graphics.SetTextContrast(0);
graphics.DrawLine(pen, prex, prey, x, y );
效果也不理想我看有的类似可以签字的软件都可以实现写出毛笔字的效果了,不知道怎么做的,请教高人,怎么能实现
image.Canvas.MoveTo(prex, prey);
image.Canvas.LineTo(x, y);
写出来的字,很生硬,有棱角,不圆滑后来用的GdiPlus
graphics := TGPGraphics.Create(self.Canvas.Handle);
pen:= TGPPen.Create(MakeColor(255, color_r, color_g, color_b), nowPenWidth);
graphics.SetSmoothingMode(999) ;
graphics.SetTextContrast(0);
graphics.DrawLine(pen, prex, prey, x, y );
效果也不理想我看有的类似可以签字的软件都可以实现写出毛笔字的效果了,不知道怎么做的,请教高人,怎么能实现
image.Canvas.MoveTo(prex, prey);
image.Canvas.LineTo(x, y);
写出来的字,很生硬,有棱角,不圆滑之后写几句,修改棱角,使之圆滑。起笔处和收笔处,加粗或收细,....总之中可以达到你需要的效果。
...
Image1.Canvas.Brush.Style:=bsClear;
Image1.Canvas.TextOut(10,10,'透明汉字');
...
begin
canvas.brush.style:=bsclear;
canvas.textout(widht div 2,height div 2, 'helloworld');
end;
Image1.Transparent=true;
Image1.Canvas.Brush.Style=bsClear;
Image1.Canvas.Font.Size=9;
Image1.Canvas.Font.Name='宋体';
Image1.Canvas.TextOut(10,10,'透明汉字');
有两个方案:
方案一. 用GDI+吧, 功能非常强
方案二. 自己实现绘制平滑线的函数. 我找了个, 速度远远慢于GDI+, 但一般也够用了.
procedure SmoothLine(canvas: TCanvas; x1,y1,x2,y2: Integer; color: TColor);
var
ea,ec: Word;
ci: Byte;
dx,dy,
d,s: Integer;
Tmp: TColor;
penr,peng,penb: Byte;
r,g,b: Byte;
begin
if(y1=y2)or(x1=x2)then begin
Canvas.Pen.Color := color;
Canvas.MoveTo(x1,y1);
Canvas.LineTo(x2,y2);
exit;
end;
if y1>y2 then begin
d:=y1; y1:=y2; y2:=d;
d:=x1; x1:=x2; x2:=d;
end;
dx:=x2-x1;
dy:=y2-y1;
if dx>-1 then s:=1
else begin
s := -1;
dx := -dx;
end;
ec:=0;
Canvas.Pixels[x1,y1]:= color;
penr := GetRValue(color);
peng := GetGValue(color);
penb := GetBValue(color);
if dy>dx then begin
ea:=(dx shl 16) div dy;
while dy>1 do begin
Dec(dy);
d:=ec;
Inc(ec,ea);
if ec<=d then Inc(x1,s);
Inc(y1);
ci:=ec shr 8; tmp:=Canvas.Pixels[x1,y1];
r := GetRValue(tmp);
g := GetGValue(tmp);
b := GetBValue(tmp);
b := ((penb*(255 xor ci))+(b*ci))shr 8;
g := ((peng*(255 xor ci))+(g*ci))shr 8;
r := ((penr*(255 xor ci))+(r*ci))shr 8;
Canvas.Pixels[x1,y1] := Windows.RGB(r,g,b); tmp:= Canvas.Pixels[x1+s,y1];
r := GetRValue(tmp);
g := GetGValue(tmp);
b := GetBValue(tmp);
b:=((penb*ci)+(b*(255 xor ci)))shr 8;
g:=((peng*ci)+(g*(255 xor ci)))shr 8;
r:=((penr*ci)+(r*(255 xor ci)))shr 8;
Canvas.Pixels[x1+s,y1] := Windows.RGB(r,g,b);
end;
end else begin
ea:=(dy shl 16)div dx;
while dx>1 do begin
Dec(dx);
d:=ec;
Inc(ec,ea);
if ec<=d then Inc(y1);
Inc(x1,s);
ci:=ec shr 8;
tmp:= Canvas.Pixels[x1,y1];
r := GetRValue(tmp);
g := GetGValue(tmp);
b := GetBValue(tmp);
b:=((penb*(255 xor ci))+(b*ci))shr 8;
g:=((peng*(255 xor ci))+(g*ci))shr 8;
r:=((penr*(255 xor ci))+(r*ci))shr 8;
Canvas.Pixels[x1,y1] := Windows.RGB(r,g,b); tmp:= Canvas.Pixels[x1,y1+1];
r := GetRValue(tmp);
g := GetGValue(tmp);
b := GetBValue(tmp);
b:=((penb*ci)+(b*(255 xor ci)))shr 8;
g:=((peng*ci)+(g*(255 xor ci)))shr 8;
r:=((penr*ci)+(r*(255 xor ci)))shr 8;
Canvas.Pixels[x1,y1+1] := Windows.RGB(r,g,b);
end;
end;
Canvas.Pixels[x2,y2]:=Canvas.Pen.Color;
end;