问题:C++代码转换成Delphi代码
描述:

c++delphiC++转delphi

哪位能帮我把下面这段代码转为delphi代码?
 这段代码用到了GDI+,因delphi从xe2才集成有GDI+,所以最好能转译为XE2版以上的代码,谢谢!
Graphics graphics(*pDC);
 CString str = "我";
 // CString fname = L"楷体_GB2312";
 int fsize = 32;
 int x=0;
 int y=0;
 int spx = 5;
 int spy = 5;
 int dx=0;
 int dy=0;
 // int order[7]={1,3,2,6,4,7,5};
 Pen tmppen1(Color(255,0,0)),tmppen2(Color(0,255,0)),tmppen3(Color(0,0,255));
 SolidBrush tmpbrush(Color(0,255,0));
 //幼圆 楷体_GB2312
 FontFamily tmpfontFamily(L"仿宋_GB2312");
 Font tmpfont(&tmpfontFamily,fsize,FontStyleRegular);
 Unit unit = tmpfont.GetUnit();
 graphics.SetPageUnit(unit);
 graphics.SetSmoothingMode(SmoothingModeHighQuality);
 GraphicsPath tmppath;
 WCHAR *strSrc;
 // LPSTR szRes;
 //获得临时变量的大小
int i = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
 strSrc = new WCHAR[i+1];
 MultiByteToWideChar(CP_ACP, 0, str, -1, strSrc, i);
 tmppath.AddString(strSrc,-1,&tmpfontFamily,FontStyleRegular,fsize,PointF(x,y),NULL);
 delete []strSrc;
 GraphicsPathIterator iterator(&tmppath);
 Rect tmprect;
 tmppath.GetBounds(&tmprect);
 dx = tmprect.Width+spx;
 int count = iterator.GetSubpathCount();
 GraphicsPath subpath;
 BOOL isClosed = FALSE;
 for (int i=0;i<>
 {
 if (i%10==0&&i!=0)
 {
 graphics.ResetTransform();
 graphics.TranslateTransform(0,(tmprect.Height+spy)*i/10);
 }
 graphics.DrawPath(&tmppen1,&tmppath);
 // iterator.Rewind();
 // for (int j=0;j<>
 {
 iterator.NextSubpath(&subpath,&isClosed);
 }
 // graphics.DrawPath(&tmppen2,&subpath);
 graphics.FillPath(&tmpbrush,&subpath);
 graphics.TranslateTransform(dx,dy);
 }
解决方案1:

procedure TForm1.Button1Click(Sender: TObject);
var
  Graphics: TGPGraphics;
  tmppen1, tmppen2, tmppen3: TGPPen;
  tmpbrush: TGPSolidBrush;
  tmpfontFamily: TGPFontFamily;
  tmpfont: TGPFont;
  tmppath, subpath: TGPGraphicsPath;
  iterator: TGPGraphicsPathIterator;
  str: string;
  fsize: integer;
  X: integer;
  Y: integer;
  spx: integer;
  spy: integer;
  dx: integer;
  dy: integer;
  i, count: integer;
  aunit: TUnit;
  tmprect: TGPRect;
  isClosed: BOOL;
  pointf: TGPPointF;
begin
  str := '我';
  fsize := 32;
  X := 0;
  Y := 0;
  spx := 5;
  spy := 5;
  dx := 0;
  dy := 0;
  Graphics := TGPGraphics.Create(Canvas.Handle);
  tmppen1 := TGPPen.Create(MakeColor(255, 0, 0));
  tmppen2 := TGPPen.Create(MakeColor(0, 255, 0));
  tmppen3 := TGPPen.Create(MakeColor(0, 0, 255));
  tmpbrush := TGPSolidBrush.Create(MakeColor(0, 255, 0));
  // 幼圆 楷体_GB2312
  tmpfontFamily := TGPFontFamily.Create('仿宋_GB2312');
  tmpfont := TGPFont.Create(&tmpfontFamily, fsize, FontStyleRegular);
  aunit := tmpfont.GetUnit();
  Graphics.SetPageUnit(aunit);
  Graphics.SetSmoothingMode(SmoothingModeHighQuality);
  pointf.X := X;
  pointf.Y := Y;
  tmppath.AddString(str, -1, tmpfontFamily, FontStyleRegular, fsize, pointf, nil);
  // delete[] strSrc;
  iterator := TGPGraphicsPathIterator.Create(tmppath);
  tmppath.GetBounds(tmprect);
  dx := tmprect.Width + spx;
  count := iterator.GetSubpathCount();
  isClosed := FALSE;
  for i := 0 to count - 1 do
  begin
    if (((i div 10) = 0) and (i <> 0)) then
    begin
      Graphics.ResetTransform();
      Graphics.TranslateTransform(0, (tmprect.Height + spy) * i / 10);
    end;
    Graphics.DrawPath(&tmppen1, &tmppath);
    iterator.NextSubpath(subpath, isClosed);
    Graphics.FillPath(&tmpbrush, &subpath);
    Graphics.TranslateTransform(dx, dy);
  end;
  tmppen1.free;
  tmppen2.free;
  tmppen3.free;
  Graphics.free;
end;

转完了有报错,剩下的你参考吧,
http://www.cnblogs.com/del/archive/2008/06/22/1227635.html

上一篇dll调用主程序函数,为什么会出错
下一篇delphi截取变量字符串
明星图片
相关文章
《C++代码转换成Delphi代码》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)