#1 Re: GDI+ » Size problems using GDI+ antialiasing function » 2012-06-08 17:48:34

Thank you very much.

It works like a charm. smile

#2 Re: GDI+ » Size problems using GDI+ antialiasing function » 2012-06-08 09:19:48

Hello.

ab wrote:

The problem comes from the fact that you scale your picture from the main window size, then use the Image1 Width/Height for the ellipsis size.

Thanks, but I can't understand where the problem is. I have changed the code, following your advice, but I get exactly the same result. I expect an ellipsis centered on the screen, but I get an image moved to the right, with the ellipsis cutted on the right edge.

I try to set exactly the same size for the Metafile, Image and Form. I suspect that the Metafile doesn't adjust to the indicated size, so drawing into MetafileCanvas and exporting it results creates a bitmap slightly larger than Image1 bitmap.

  MF.Width := frmMain.Width;
  MF.Height := frmMain.Height;
  Image1.Width := frmMain.Width;
  Image1.Height := frmMain.Height;
  Image1.Top := 0;
  Image1.Left := 0;

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

  MetafileCanvas.Brush.Color := clRed;
  MetafileCanvas.Brush.Style := bsDiagCross;
  MetafileCanvas.Ellipse(50, 50, frmMain.Width - 50, frmMain.Height - 50);

I only get the expected result at a form resolution of 1209 x 907, but I don't know what is especial about that resolution. It seems that the Metafile Canvas always draws at 1209 x 907 and cuts to the desired result, but I don't understand how or why it does that.

Thanks for your kind help.

#3 GDI+ » Size problems using GDI+ antialiasing function » 2012-06-07 18:59:30

emarc
Replies: 4

Regards,

We are using your great library in order to apply antialiasing to several vectorial shapes drawed at runtime. But when it must be shown at screen, it doesn't fit on the designed size.

I attach a simple sample to show this behaviour (you only need to add an Image1 TImage into a new form to run it)

It should show an ellipsis at 50 pixels from every screen border, but it doesn't.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TfrmMain = class(TForm)
    Image1: TImage;
    procedure FormResize(Sender: TObject);
  private
  public
    procedure DrawTest;
  end;

var
  frmMain: TfrmMain;

implementation 

{$R *.dfm}

Uses Math, SynGdiPlus;

procedure TfrmMain.FormResize(Sender: TObject);
begin
  DrawTest;
end;

procedure TfrmMain.DrawTest;
var Bmp: TBitmap;
    MF: TMetaFile;
    MetafileCanvas: TMetafileCanvas;
    DC: HDC;
    ScreenLogPixels: Integer;
begin
  Gdip := TGDIPlusFull.Create('gdiplus.dll');       // Dibujamos sobre un TMetafile sobre el cual podemos hacer una llamada GDI+ a aplicar Antialiasing
  MF := TMetaFile.Create;
  DC := GetDC(0);
  ScreenLogPixels := GetDeviceCaps(DC, LOGPIXELSY);
  MF.Inch := ScreenLogPixels;
  MF.Width := frmMain.Width;
  MF.Height := frmMain.Height;

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

  MetafileCanvas.Brush.Color := clRed;
  MetafileCanvas.Brush.Style := bsDiagCross;
  MetafileCanvas.Ellipse(50, 50, Image1.Width - 50, Image1.Height - 50);

  ReleaseDC(0, DC);
  MetafileCanvas.Free;
  MF.Enhanced := FALSE;

  Bmp := Gdip.DrawAntiAliased(MF,100,100);

  Image1.Picture.Assign(Bmp);
  MF.Destroy;
  Self.BringToFront;
end;

end.

Can you tell us what we are doing wrong ?

Thank you.

Board footer

Powered by FluxBB