Synopse Open Source - Tag - TIFmORMot MVC / SOA / ORM and friends2024-02-02T17:08:25+00:00urn:md5:cc547126eb580a9adbec2349d7c65274DotclearAntialiased drawing from TMetaFileurn:md5:60fd60000baf364dcc593cffa475812f2010-04-02T14:25:00+02:002010-09-23T15:03:51+02:00AB4327-GANDIOpen Source librariesblogDelphiGDIGDIPlusGIFJPEGTIF<p>The new version of our Open Source <em>SynGdiPlus</em> unit
does provide a lot of new features: <br />
- dynamic linking (your program runs even on Windows 98/2000), without the
gdiplus.dll library<br />
- use version 1.1 of GDI+ if available on your system (under Vista/Seven or the
one embedded since Office 2003)<br />
- can convert from a <em>TMetaFile</em> (i.e. emf) into a GDI+ metafile (i.e.
emf+)<br />
- can draw <em>TMetaFiles</em> into any canvas, with
GDI+ anti-aliasing!</p> <p>All GDI+ Delphi conversions I know about are statically-linked. This
has two main drawbacks:<br />
- Your application can't run without the gdiplus.dll library (e.g. under
Windows 2000);<br />
- 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.</p>
<p>Our <em>SynGdiPlus</em> unit allow your application to use the
GDI+ library:<br />
- If no gdiplus.dll is available, use raw GDI32 drawings;<br />
- use latest 1.1 version of GDI+, supplied with Vista and Seven;<br />
- 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);<br />
- drawing using a <em>TMetaFileCanvas</em> with standard VCL calls, then draw
it with anti-aliasing using GDI+;<br />
- if you only need GIF, JPEG, TIFF and PNG image support, the <em>TGDIPlus</em>
class is enough for your.</p>
<p>The new <em>TGDIPlusFull</em> class:<br />
- Inherits from <em>TGDIPlus</em> class, so handle GIF, JPEG, TIFF and PNG
images: <br />
- Add most GDI+ drawing methods (graphics, pens, brushes, lines, polygons,
rectangles, text...) for direct drawing;<br />
- Allow to convert a <em>TMetaFile</em> into a emf+ metafile, ready to be drawn
on any Canvas, with anti-aliasing;<br />
- Allow to convert a <em>TMetaFile</em> into a
TBitmap, with anti-aliasing.</p>
<p>How does it work?</p>
<p>If GDI+ version 1.1 is installed, one hidden method is called for the
conversion, which should be quite perfect in all cases.</p>
<p>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 <em>TMetaFile</em> 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).<br />
If you need some other methods, you are free to add them, and contribute to
this open source project!</p>
<p>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 <em>TGDIPLusFull</em> class methods.</p>
<p>Some sample code:</p>
<pre>
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);
</pre>
<p>The Gdip instance will be freed by the unit.</p>
<p>You can freely download the full source code of this unit (licensed under a
MPL/GPL/LGPL tri-license) from <a href="http://synopse.info/files/SynGdiPlus.zip">http://synopse.info/files/SynGdiPlus.zip</a></p>
<p>You can use our library to use VCL TCanvas methods to paint, then draw it
with GDI+ with antialiasing.<br />
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.</p>
<p>Of course, there are always some <em>TPicture</em> descendant in our
unit, so that you could be able to read or write GIF, PNG, JPEG or TIFF
pictures.</p>
<p>Comments and feedback are welcome on our forum: <a href="http://synopse.info/forum/viewforum.php?id=4">http://synopse.info/forum/viewforum.php?id=4</a></p>GIF, TIF, PNG and JPG pictures TGraphic read/write via GDI+urn:md5:49645dde480607a168dfafee574c4e802010-03-20T15:02:00+01:002010-09-23T15:13:54+02:00AB4327-GANDIOpen Source librariesblogDelphiGDIGDIPlusGIFJPEGPNGTIF<p>Implements <em>TGraphic</em> descendants able to load <strong>and
save</strong> GIF, TIF, PNG and JPG pictures, using the GDI+ library. Freeware
Opensource component, licensed under a MPL/GPL/LGPL tri-license. Works from
Delphi 3 to 2010.</p> <p>By adding the <em>SynGdiPlus</em> unit to your uses clause,
these <em>TGraphic</em> descendants are registered in your
application to load GIF, TIF, PNG and JPG pictures. Use
<em>TPicture.LoadFromFile()</em> method with the right extension, and the
corresponding decoder will be used. </p>
<p>This unit implements its own GDI+ API functions, in a safe dynamic manner.
Even if you don't have GDI+ installed on the system (e.g. with Windows 2000),
the executable will launch - but all GIF, TIF, PNG and JPG pictures
loading and saving won't work. Please note that the GDI+ library is
available on all Windows Operating System since Windows XP (including Vista and
Seven).</p>
<p>Since all the decoding and encoding is done by the GDI+ library, this unit
adds much less code to your executable than the standard JPEG and PNG
units.</p>
<p>These classes handle the <em>saving</em> of the pictures. Most GDI+
implementation just allows you to load pictures. This unit handle all the
saving and conversion between formats. You can easily load an TIF, then save it
as a JPG file with a specified Compression Quality, via the <em>SaveAs()</em>
method.</p>
<p>Some easy one line helper functions are available:</p>
<pre>
function LoadFrom(const FileName: TFileName): TBitmap;
</pre>
<div>
<pre>
procedure SaveAs(Graphic: TPersistent; Stream: TStream; Format: TGDIPPictureType; CompressionQuality: integer=80); overload;
</pre>
<div>
<pre>
procedure SaveAs(Graphic: TPersistent; const FileName: TFileName; Format: TGDIPPictureType; CompressionQuality: integer=80); overload;
</pre>
<div>The full source code of this unit (intended to work from Delphi 3 to
2010) is freely downloadable from <a href="http://synopse.info/files/SynGdiPlus.zip">http://synopse.info/files/SynGdiPlus.zip</a></div>
<div>I'll try to add some more GDI+ commands, a canvas-like implementation, in
the future.</div>
</div>
</div>
<div>Comments and feedback are <a href="http://synopse.info/forum/viewtopic.php?id=115">welcome on our
forum</a>.</div>