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
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.
Of course, there are always some TPicture descendant in our unit, so that you could be able to read or write GIF, PNG, JPEG or TIFF pictures.
Comments and feedback are welcome on our forum: http://synopse.info/forum/viewforum.php?id=4
3 reactions
1 From Wayne - 22/04/2010, 16:28
I have tried this code out and cant seem to get it to work. I have used the test project that comes in the zip download.
I changed the name of the files to match some I have on my hard drive. I never get anything to draw. I am mostly concerned about loading an EMF+ file from disk and rendering it to the screen. However I couldnt even get a plain EMF file to render.
You can reach me at wayne.fulcher@dbsinc.com
2 From A.Bouchez - 23/04/2010, 07:28
We use this library in several projects, running fine from Windows 2000 to Windows Seven, without any problems.
But it was tested under Delphi 7. Other versions should work, but were not fully tested.
Which version of the Delphi compiler do you use?
3 From xalion - 27/04/2010, 10:56
It can't work with apache web module.
but when change
initialization
// Gdip.Create('gdiplus.dll');
// GdipTest('d:\Data\Pictures\Sample Pictures\Tree.jpg');
finalization
// Gdip.Free;
and in webmodule create event I add Gdip.Create('gdiplus.dll');
it works fine.