如何在图像中沿弧线渲染文本? [英] How do I render text along an arc in an image?

查看:140
本文介绍了如何在图像中沿弧线渲染文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Delphi 7中使用以下代码来沿DVD的弯曲边缘绘制版权文本.我们使用的是旧版本的Graphics32.

I have the following code in Delphi 7 to draw Copyright text along the curved edge of a DVD. We are using an old version of Graphics32.

我们正在使用来自Graphics32的最新代码切换到Delphi XE5,并且该代码不再编译;特别是LoadArcCurve和drawingBuffer.RenderFittedText不再作为方法存在.

We are switching to Delphi XE5 with the latest code from Graphics32 and this code no longer compiles; in particular LoadArcCurve and drawingBuffer.RenderFittedText no longer exists as methods.

procedure TCDLabel.DrawCopyrightText(const drawingBuffer: TBitmap32Ex);
var
  FixedPointArray : TArrayOfFixedPoint;
  Center : TFixedPoint;
  vAngle1 : double;
  vAngle2 : double;
  radius : integer;
  CopyrightText : string;
  textColor : TColor32;
begin
  radius := (fImageSize div 2) - 30;
  UpdateTextTransform(8{2.3}, drawingBuffer);
  Center.x := GR32.Fixed(fImageSize div 2);
  Center.y := GR32.Fixed(fImageSize div 2);
  vAngle1 := DegToRad(-130);
  textColor := clWhite32;
  vAngle2 := DegToRad(0);
  LoadArcCurve(Center, GR32.Fixed(radius), GR32.Fixed(radius), vAngle1, vAngle2, FixedPointArray);
  CopyrightText := Format('%s %s Dystopia Unlimited. All rights reserved.', [GetCopyrightSymbol, fCopyrightYears]);
  drawingBuffer.RenderFittedText(CopyrightText, textColor, pdoAntialising or pdoFilling, FixedPointArray);
  FixedPointArray := NIL;
end; {DrawCopyrightText}

我在Delphi XE5中使用以下最新的Graphic32代码编写了以下代码段,并尝试了各种其他类似方法,但均未成功.

I have the following code snippet in Delphi XE5 using the latest Graphic32 code and have attempted various other similar methods without success.

canvas := TCanvas32.Create(drawingBuffer); // drawingBuffer is a TBitmap32
try
  canvas.Brushes.Add(TStrokeBrush);
  canvas.Brushes[0].Visible := TRUE;
  (canvas.Brushes[0] as TStrokeBrush).StrokeWidth := 2;
  (canvas.Brushes[0] as TStrokeBrush).FillColor := clWhite32;

  canvas.Path.BeginPath;
  canvas.Path.Arc(Center, -130, 0, radius);
  canvas.Path.EndPath;
  TextToPath(drawingBuffer.Font.Handle, canvas.Path, FloatRect(0, 0, fImageSize, fImageSize), CopyrightText);

当我需要绘制到TBitmap32上时,可以在新Graphics32中找到的所有示例似乎都直接绘制到了Delphi控件画布上.

All of the examples in the new Graphics32 that I can find appear to draw directly onto a Delphi control canvas while I am required to draw onto a TBitmap32.

如何使用Delphi XE5和最新版本的Graphics32在图像/位图中沿弧线渲染文本?

How do I render text along an arc in an image/bitmap using Delphi XE5 and the latest version of Graphics32?

推荐答案

我认为实现您所描述内容的最佳方法是使用Angus Johnson对graphics32的出色扩展,

I think that the best way to implement what you describe is to use Angus Johnson's excellent extension to graphics32, GR32_Text.

这篇关于如何在图像中沿弧线渲染文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆