tags:

views:

470

answers:

6

Hi.
I need a very simple function to draw a bunch of lines with anti-aliasing. It has to follow Delphi paradigm: self contained and SYSTEM INDEPENDENT (no DLL hell), fast, simple. Anybody knows such a library?

Until now I have tried:

WuLine
swissdelphicenter.ch/torry/showcode.php?id=1812
I don't think that Peter Bone, the author of this code ever run it. It takes one second to draw a single line! It is obviously only for educational purposes :)

Anti aliased drawing from TMetaFile
Link: blog.synopse.info/post/2010/04/02/Antialiased-drawing-from-TMetaFile
Haven't really tried this yet (I may do it soon). It works only with TMetaFiles. It only loads an EMF file and draw it using anti aliasing functions. Plus, much code on that web site is only demonstrational/educational.

Image32
Very nice library - most complete until now. I am using this currently in my program. Totally overkill for what I need.
Disadvantages:

  • The footprint added to application is pretty big.
  • Really difficult to use.
  • You need to go really deep in its obscure documentation even for simple tasks.
  • Buggy!
  • No recent updates (to fix the bugs)

Anti-Grain Geometry library
The library needs a decent installer. The writers of the library are Linux/Mac users. The Windows implementation looks weird.

Xiaolin Wu's based function (by Andreas Rejbrand)
Best solution until now. However, it works when you have to draw only 10-20 lines, else it is too slow.


It looks like I have to explain why I don't like large 3rd party libraries and VCL's:

  • you have to install them
  • large library means large number of bugs which means
  • you have to check for updates (and install them again)
  • when you reinstall Delphi, you have to install them one more time (yes I hate installing VCLs)
  • for VCLs, it means you have to load some extra icons in your already crowded palette.
  • (sometimes) no support
  • LARGE footprint added to your application size
  • large library means (well not always but in most cases) difficult to use - more difficult than you need.
  • (for external DLLs and API) your application becomes system-dependent - really nasty!
+7  A: 

I believe GDI+ does anti-aliased drawing (by default), I don't know if recent Delphi versions have a GdiPlus.pas, but there are copies available online.

Stijn Sanders
GDI+ doesn't do anti-aliasing of GDI EMF/TMetaFile/Canvas content. It only renders anti-aliasing with GDI+/EMF+/Canvas metafiles. So in order to use anti-aliasing, you'll have to rewrite all you drawings using GDI+ methods. Our GdiPlus library allows anti-aliased drawings using "normal" VCL canvas commands: draw into a TMetaFile, then write it using our library. It's fast and easy.
A.Bouchez
I read too fast. For drawing just lines, you can use GdiPlus methods. But you'll have to learn about GdiPlus drawing, whereas with our library you'll use plain old VCL TCanvas methods, just as usual. If you'd like to use GdiPlus drawing, I recommend using the http://www.bilsen.com/gdiplus/index.shtml library, which is much easier to use than previous conversions, but requires Delphi 2009/2010/XE.
A.Bouchez
@Bouchez - does it work on systems previous to WinXP? does it works on ALL WinXP OSs or the user has to install some updates?
Altar
Sorry. Forget about it. Does fit my requirements (D7).
Altar
Our SynGdiPlus library work with Delphi 7 up to Delphi 2010. It works on all Windows since XP (even without Service Pack), and you'll have to deploy a gdiplus.dll if you want your application work with Windows 2000 (it will search for gdiplus.dll in the Office folder, also). If the gdiplus.dll is not available, it will use normal GDI to draw, and your code will work (since the library is dynamically linked to the exe, whereas all other gdiplus libraries I know use static linking), but with no anti-aliaising.
A.Bouchez
+6  A: 
Andreas Rejbrand
This is really slow, and is a proof of concept more than a useful function. Playing with metafiles need a lot of commands, much more than only line drawing. You should go and see http://www.crossgl.com/aggpas for example or http://graphics32.org/wiki for a more complete drawing library.
A.Bouchez
Or of course, use GdiPlus, which is shipped with every Windows since XP.
A.Bouchez
@A.Bouchez: I do not understand what you are talking about. I do not play with metafiles. But it is well-known that the `Pixels` property is slow. If one would draw the line on a two-dimensional array of pixels, and then use the `scanline` property to convert to/from the canvas, you could probably improve the performance significantly. But if you do not need to draw more than (say) a hundred lines, this is "fast enough" as it stands.
Andreas Rejbrand
A.Bouchez
@A.Bouchez: Drawing lines with semi-transparent anti-aliasing on a non-uniform background is trivial using only a minor modification to mmy code above. Indeed, `c` is the transparency of the pixel, and given background colour, forground colour, and transparency, blending is trivial. But of course, depending on your needs, a full library might be needed. But I got the impression that the OP wanted something light-weight just to draw straight lines.
Andreas Rejbrand
@Andreas- Yes, I need something simple and compact. I already use Graphics32 but this is overkill. OpenGL is neither small, neither compact :) But the source code provided is the best answer until now.
Altar
@Andreas - Thanks for your code. It is the most simple and most elegant solution!!!! But (I hope I am not a rude brat) can you give few more clues about how to start in making the code to support colors? I am not really into graphics. I am not asking for code (you already did a lot) only some hints about how to start. Thanks a lot!
Altar
@Andreas - PS: I have seen your web site ( http://english.rejbrand.se/AlgoSim ). Impressive. It seems you are really into graphics.
Altar
@Altar: Thank you. I updated the code so that it will work on a variable, coloured background.
Andreas Rejbrand
Wow. Thank you so much. I compared the code and now I see it. Thanks again!
Altar
@Andreas - I get 'Range check error' in procedure plot. It works however, if you just ignore the error with {$R-}. Anyway, I just realized that the function is too slow for the amount of lines I want to draw.
Altar
@Altar: Yes, the `TBitmap.Pixels` property is amazingly slow. Therefore, when I work with graphics, I do all pixel manipulation on a two-dimensional array of integers (TColors, or TRGBQUADs), and then, when I am done and want to display the bitmap, I convert the array to a normal GDI bitmap. I updated with some code that illustrates the idea. There seems to be a minor bug in the code, but at the moment I am way too tired to debug.
Andreas Rejbrand
A: 

Give a try to Anti-Grain Geometry library

Luca Guzzon
This library seems complex. Do you know if I can use it as simply as DrawAntiAliasLine()? Or I have to perform complex stunts like I have to do with Graphics32?
Altar
+1  A: 

Download Graphics32. Create a new TBitmap32 instance. Call the TBitmap32.RenderText method:

procedure TBitmap32.RenderText(X, Y: Integer; const Text: String; AALevel: Integer; Color: TColor32);

if AALevel > -1 then you should get anti-aliased text.

When you're done writing string(s) on your TBitmap32 instance, then you can draw this TBitmap32 instance to any Canvas using the DrawTo method:

procedure TBitmap32.DrawTo(hDst: HDC; DstX, DstY: Integer);
Stefan
Please read my post again. I am doing this already. What I need is "I need a very simple library to draw a bunch of lines with anti-aliasing. It has to follow Delphi paradigm: self contained and SYSTEM INDEPENDENT (no DLL hell), fast, simple."
Altar
I believe Graphics32 meets most (if not all) of your requests. It is self-contained, platform-independent (Free Pascal and Lazarus on Windows and OSX), and pretty fast. Whether or not it is simple enough, well I guess that's the eye of the beholder.
Stefan
Most but not all. This is why I changing it. If it would have meet all my requirements I wouldn't have been posting here. Right? - To make it simple: I want something better than Graphics32.
Altar
+1  A: 

You can try TAgg2D. It is a simplified API for 2D drawing over AggPas. So you can use simple functions like:

  • Line (x1, y1, x2, y2 )
  • Rectangle (x1, y1, x2, y2 )
  • RoundedRect (x1, y1, x2, y2, r )

Easy!

Daniel Luyo
Sound good. Thanks!
Altar
A: 

Here are solutions that I know:

  1. DtpDocument Very good Vector Editor. Lot's of features. Anti Aliasing supported very well. Commercial Solution
  2. ImageEn It's fast enough for me. Commercial Soltuion
  3. Cairo Graphics It's very fast and used by Mozilla in Firefox for rendering. You can easily use Cairo in Delphi by this tutorial. I strongly recommand you take a shot.
Muhamamd