现在要做一个类似大头贴的软件,拍完照片后,可以用鼠标来签名,功能实现了,但签字的效果一直不理想,原来用的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 );
效果也不理想我看有的类似可以签字的软件都可以实现写出毛笔字的效果了,不知道怎么做的,请教高人,怎么能实现

解决方案 »

  1.   

    這個肯定要使用Canvas去實現自繪了
      

  2.   

    使用原来用的Canvas
    image.Canvas.MoveTo(prex, prey);
    image.Canvas.LineTo(x, y);
    写出来的字,很生硬,有棱角,不圆滑之后写几句,修改棱角,使之圆滑。起笔处和收笔处,加粗或收细,....总之中可以达到你需要的效果。
      

  3.   

    AAFont组件中有修改棱角,使之圆滑的算法,楼主可以参考一下。
      

  4.   

    pen的样式有好几种,四方形,圆形,你可以设置不同的样式,多试一下,另外。如果做画笔功能,可以考虑用图片来替代,做出不同的效果。
      

  5.   

    如果只是在image上寫字(非MOUSE),那麼可以這樣:只需设置CanvasBrush.Style为bsClear就OK,如: 
    ... 
        Image1.Canvas.Brush.Style:=bsClear; 
        Image1.Canvas.TextOut(10,10,'透明汉字'); 
    ...
      

  6.   

    這樣也行:with image1 do 
      begin 
        canvas.brush.style:=bsclear; 
        canvas.textout(widht div 2,height div 2, 'helloworld'); 
      end; 
      

  7.   

    這樣也可以:(如果有Bitmap的话要把Transparent去掉,不然会闪烁)     
        Image1.Transparent=true; 
        Image1.Canvas.Brush.Style=bsClear; 
        Image1.Canvas.Font.Size=9; 
        Image1.Canvas.Font.Name='宋体'; 
        Image1.Canvas.TextOut(10,10,'透明汉字'); 
      

  8.   

    //不能画线在timage的mousemove事件中 ,在鼠标移动过的每点画一个实心圆,
      

  9.   

    你要的是抗锯齿的效果吧?
    有两个方案: 
    方案一. 用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;