본문 바로가기
Application/Delphi Lecture

GDI+ 를 이용한 스트링 회전

by 현이빈이 2008. 8. 13.
반응형
The transforms do work, here's some sample code (GDI+) that mirrors around
 the x, y and x and y. Drop a TPaintbox on the form set the onpaint event
 to the following and you're away.

 cheers,
 Dave

 procedure TForm29.PaintBox1Paint(Sender: TObject);
 var
   graphics : TGPGraphics;
   FontFamily: TGPFontFamily;
   Font: TGPFont;
   SolidBrush: TGPSolidBrush;
   Matrix : TGPmatrix;
   SolidPen : TGPPen;
   r : TGPrectF;
   GraphicsPath : TGPGraphicsPath;
 begin
   graphics   := TGPGraphics.Create(PaintBox1.Canvas.handle);
   FontFamily := TGPFontFamily.Create('Times New Roman');
   Font       := TGPFont.Create(FontFamily, 32, FontStyleRegular,
 UnitPixel);
   SolidBrush := TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
   SolidPen := TGPPen.Create(MakeColor(255, 0, 0, 255));

 //  graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);

 // so you can see the box
   graphics.drawRectangle(SolidPen, MakeRect(0,0,PaintBox1.Width-1,
 PaintBox1.height-1));

 // the normal text offset to the right half of the paintbox
   graphics.TranslateTransform(PaintBox1.width div 2, 0);
   graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
 solidBrush);

   // x mirror
   matrix := TGPMatrix.Create(-1,0,0,1,PaintBox1.width div 2,0);
   graphics.settransform(matrix);
   graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
 solidBrush);
   matrix.free;

   // y mirror
   matrix := TGPMatrix.Create(1,0,0,-1,PaintBox1.width div
 2,PaintBox1.height);
   graphics.settransform(matrix);
   graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
 solidBrush);
   matrix.free;

   // x and y mirror
   matrix := TGPMatrix.Create(-1,0,0,1,PaintBox1.width div 2,0);
   graphics.settransform(matrix);
   matrix.free;
   matrix := TGPMatrix.Create(1,0,0,-1,0,PaintBox1.height);
   graphics.multiplytransform(matrix);
   graphics.DrawString('AntiAlias', -1, font, MakePoint(0.0, 0.0),
 solidBrush);
   matrix.free;

   graphics.Free;
   FontFamily.Free;
   Font.Free;
   SolidBrush.Free;
 end; 

반응형