#1 2016-11-11 16:43:06

ethanyager
Member
Registered: 2016-04-05
Posts: 3

Pixelated TextOut from TMetaFile

I am using the previous example of antialiasing from a TMetaFile. It works great for lines but I can't get smooth aa text like I usually get with GDI+. Not sure what I am doing wrong. In the example below, I added one text out and one line. If I modify this example to use regular GDI rendering the text will appear smoother than when antialiasing is turned on.

Here is my code:

var Bmp: TBitmap;
    MF: TMetaFile;
    MetafileCanvas: TMetafileCanvas;
    DC: HDC;
    ScreenLogPixels: Integer;
    LogFont: TLogFont;
begin
  MF := TMetaFile.Create;
  DC := GetDC(0);
  ScreenLogPixels := GetDeviceCaps(DC, LOGPIXELSY);
  MF.Inch := ScreenLogPixels;
  MF.Width := Form1.Width;
  MF.Height := Form1.Height;

  MetafileCanvas := TMetafileCanvas.Create(MF, DC);

  MetafileCanvas.font.Color := clblue;
  MetafileCanvas.font.Name := 'Calibri';
  MetafileCanvas.font.Size := 150;

  MetafileCanvas.TextOut(100, 100, 'Text Out AaBbCcDdEeFfGgHhIi');
  MetaFileCanvas.Pen.Width := 2;
  MetaFileCanvas.MoveTo(100,300);
  MetaFileCanvas.LineTo(900,600);

  ReleaseDC(0, DC);


  MetafileCanvas.Free;
  MF.Enhanced := FALSE;

  Bmp := TBitmap.Create;
  BMp.Width := Form1.Width;
  Bmp.Height := Form1.height;

  ExpectGDIPlusFull;

  Bmp := Gdip.DrawAntiAliased(MF,100,100, smAntiAlias);
  Canv.Draw(0,0,bmp);

  bmp.Free;
  MF.Destroy;
end;

Last edited by ethanyager (2016-11-11 16:51:26)

Offline

Board footer

Powered by FluxBB