#1 2010-06-21 16:03:13

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,569
Website

Antialiased drawing from TMetaFile

The new version of our Open Source SynGdiPlus  unit does provide a lot of new features:
- dynamic linking (your program runs even on Windows 98/2000), without the gdiplus.dll library
- use version 1.1 of GDI+ if available on your system (under Vista/Seven or the one embedded since Office 2003)
- can convert from a TMetaFile (i.e. emf) into a GDI+ metafile (i.e. emf+)
- can draw TMetaFiles into any canvas, with GDI+ anti-aliasing!

All GDI+ Delphi conversions I know about are statically-linked. This has two main drawbacks:
- Your application can't run without the gdiplus.dll library (e.g. under Windows 2000);
- On XP, you link only to the 1.0 version of GDI+, even if you have the 1.1 version installed in your Office 2003/2007 directory.

Our SynGdiPlus unit allow your application to use the GDI+ library:
- If no gdiplus.dll is available, use raw GDI32 drawings;
- use latest 1.1 version of GDI+, supplied with Vista and Seven;
- use the 1.1 version of GDI+, supplied with Office 2003/2007, if you have one of those installed on your computer (works under 2000 or XP);
- drawing using a TMetaFileCanvas with standard VCL calls, then draw it with anti-aliasing using GDI+;
- if you only need GIF, JPEG, TIFF and PNG image support, the TGDIPlus class is enough for your.

The new TGDIPlusFull class:
- Inherits from TGDIPlus class, so handle GIF, JPEG, TIFF and PNG images:
- Add most GDI+ drawing methods (graphics, pens, brushes, lines, polygons, rectangles, text...) for direct drawing;
- Allow to convert a TMetaFile into a emf+ metafile, ready to be drawn on any Canvas, with anti-aliasing;
- Allow to convert a TMetaFile into a TBitmap, with anti-aliasing.

How does it work?

If GDI+ version 1.1 is installed, one hidden method is called for the conversion, which should be quite perfect in all cases.

If GDI+ version 1.0 only is installed (this is the case on a raw XP system, or with the freely downloadable gdiplus.dll library - Micro$oft denied the right to distribute version 1.1 of gdiplus.dll separately), a special method enumerate the TMetaFile content, and draw the corresponding content using pure GDI+ commands. Most of the drawing is handled by this pure delphi method, but some content is missing yet (like drawing a bitmap embedded in the metafile, or some barely used commands).
If you need some other methods, you are free to add them, and contribute to this open source project!

In practice, you use a TMetaFileCanvas to draw your content using normal VCL calls (you can load external emf files and draw them inside - it's tested), then you convert it to a bitmap or draw it to a HDC using the corresponding TGDIPLusFull class methods.

Some sample code:

Gdip := TGDIPlusFull.Create;
MF := TMetaFile.Create;
MF.LoadFromFile(Files[Tag]);
Bmp := Gdip.DrawAntiAliased(MF,100,100); // 100% zoom in both axis
img1.Picture.Assign(Bmp);

The Gdip instance will be freed by the unit.

You can freely download the full source code of this unit (licensed under a MPL/GPL/LGPL tri-license) from http://synopse.info/files/SynGdiPlus.zip

Offline

#2 2010-09-02 12:33:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,569
Website

Re: Antialiased drawing from TMetaFile

You can use our library to use VCL TCanvas methods to paint, then draw it with GDI+ with antialiasing.

Just use a TMetaFileCanvas from a temporary TMetaFile created in memory. Draw in the TMetaFileCanvas just as usual, with your VCL methods, then use DrawAntiAliased to get a bitmap representation of it.

See for example the TGDIPages.PreviewPaint method in our SQLite3Pages unit - cf. http://synopse.info/fossil/artifact?name=3202e8f0c0cda -if you want to use this anti-aliased drawing in any control.
It uses a temporary bitmap, which avoid any flicker on drawing, and is used to fast redraw the component content: antialiased drawing is only made once, and should be done only if resize or refresh is necessary.

Offline

Board footer

Powered by FluxBB