![Fast Graphics Library For Delphi | Embarcadero RAD Studio Delphi C++Builder Blogs fast graphics library for delphi](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/12/Fast-Graphics-Library-For-Delphi-3436973.png?resize=1140%2C675&ssl=1)
Graphics32 is a graphics library for Delphi. Optimized for 32-bit pixel formats, it provides fast operations with pixels and graphics primitives. In most cases, Graphics32 considerably outperforms the standard TBitmap/TCanvas methods.
However, they are rewritten to accelerate and optimize drawing on 32-bit device-independent bitmaps (DIBs). It also includes a few new options.
Features of the Graphics32 library:
- Fast per-pixel access is up to 100 times faster compared to standard TCanvas/TBitmap
- High-performance Bitmap alpha blending
- Arbitrary polygon transformations and custom fillings
- Bitmap resampling with high-quality reconstruction filters
- Affine transformations of bitmaps: rotations, scaling
- Flexible supersampling implementation for maximum sampling quality
- Multiple customizable, easy-to-use overlay layers
- Platform independent code
Graphics32 has some important differences from the standard components. It does not heavily rely on Windows GDI; most of the functions are reimplemented and optimized specifically for 32-bit pixel format.
Here is some sample code from the Graphics32 ArrowHead example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
procedure TFmArrowHead.ReDraw; var Box : array [0..1] of TArrayOfFloatPoint; Poly, ArrowPts: TArrayOfFloatPoint; StartPoint, EndPoint, StartOffsetPt, EndOffsetPt: TFloatPoint; Delta: TFloatPoint; Arrow: TArrowHeadAbstract; GradientFiller: TLinearGradientPolygonFiller; const StartArrowColor: TColor32 = $60009900; StartArrowPenColor: TColor32 = $FF339900; EndArrowColor: TColor32 = $600000AA; EndArrowPenColor: TColor32 = $FF0033AA; begin ImgView32.Bitmap.Clear(clWhite32); case RgpArrowStyle.ItemIndex of 1: Arrow := TArrowHeadSimple.Create(ArrowSize); 2: Arrow := TArrowHeadFourPt.Create(ArrowSize); 3: Arrow := TArrowHeadDiamond.Create(ArrowSize); 4: Arrow := TArrowHeadCircle.Create(ArrowSize); else Arrow := nil; end; Box[0] := MakeBox(FBoxCenter[0], CBoxSize); Box[1] := MakeBox(FBoxCenter[1], CBoxSize); FBitmapFiller.Pattern := FPattern[0]; DashLineFS(ImgView32.Bitmap, Box[0], FDashes, FBitmapFiller, EndArrowPenColor, True, CBorderSize, 1.5); FBitmapFiller.Pattern := FPattern[1]; DashLineFS(ImgView32.Bitmap, Box[1], FDashes, FBitmapFiller, EndArrowPenColor, True, CBorderSize, 1.5); // now accommodate for CBorderSize width as above ... Box[0] := MakeBox(FBoxCenter[0], CBoxSizePlus); Box[1] := MakeBox(FBoxCenter[1], CBoxSizePlus); if BoxesOverlap(FBoxCenter[0], FBoxCenter[1], CBoxSizePlus) then begin StartPoint := FBoxCenter[0]; EndPoint := FBoxCenter[1]; end else begin StartPoint := GetNearestPointOnBox(FBoxCenter[1], FBoxCenter[0], Box[0]); EndPoint := GetNearestPointOnBox(FBoxCenter[0], FBoxCenter[1], Box[1]); end; Delta.X := StartPoint.X - FBoxCenter[0].X; Delta.Y := StartPoint.Y - FBoxCenter[0].Y; if Abs(Delta.X) > Abs(Delta.Y) then StartOffsetPt := FloatPoint(StartPoint.X + Delta.X * 2, StartPoint.Y) else StartOffsetPt := FloatPoint(StartPoint.X, StartPoint.Y + Delta.Y *2); Delta.X := EndPoint.X - FBoxCenter[1].X; Delta.Y := EndPoint.Y - FBoxCenter[1].Y; if Abs(Delta.X) > Abs(Delta.Y) then EndOffsetPt := FloatPoint(EndPoint.X + Delta.X * 2, EndPoint.Y) else EndOffsetPt := FloatPoint(EndPoint.X, EndPoint.Y + Delta.Y * 2); Poly := BuildPolygonF([StartPoint.X, StartPoint.Y, StartOffsetPt.X, StartOffsetPt.Y, EndOffsetPt.X, EndOffsetPt.Y, EndPoint.X, EndPoint.Y]); Poly := MakeBezierCurve(Poly); if Assigned(Arrow) then begin // shorten path at specified end(s) and draw ... case RgpPosition.ItemIndex of 0: Poly := Shorten(Poly, ArrowSize, lpStart); 1: Poly := Shorten(Poly, ArrowSize, lpEnd); 2: Poly := Shorten(Poly, ArrowSize, lpBoth); end; // draw the connecting line ... GradientFiller := TLinearGradientPolygonFiller.Create; try GradientFiller.SimpleGradient(Poly[0], StartArrowPenColor, Poly[High(Poly)], EndArrowPenColor); PolylineFS(ImgView32.Bitmap, Poly, GradientFiller, False, TbrLineWidth.Position); finally GradientFiller.Free; end; // draw specified arrows ... if RgpPosition.ItemIndex <> 1 then begin ArrowPts := Arrow.GetPoints(Poly, False); PolygonFS(ImgView32.Bitmap, ArrowPts, StartArrowColor); PolylineFS(ImgView32.Bitmap, ArrowPts, StartArrowPenColor, True, TbrLineWidth.Position); end; if RgpPosition.ItemIndex <> 0 then begin ArrowPts := Arrow.GetPoints(Poly, True); PolygonFS(ImgView32.Bitmap, ArrowPts, EndArrowColor); PolylineFS(ImgView32.Bitmap, ArrowPts, EndArrowPenColor, True, TbrLineWidth.Position); end; end else PolylineFS(ImgView32.Bitmap, Poly, clBlack32, False, TbrLineWidth.Position); end; |
Other drawing examples include:
- AntiAliasing
- ArrowHead
- Benchmark
- Blurs
- Clipper
- CubicSpline
- Curves
- GammaBlur
- GammaCorrection
- GradFills
- GradLines
- GradSampler
- Grow
- LineStippling
- Lion
- MeshGradients
- Polygons
- RenderText
- ScatterPlot
- SvgPath
- TextVPR
- VertexReduction
Head over to GitHub and check out the Graphics32 library here!
With the use of Windows IDE, you can build and enhance Delphi Windows Applications without any hindrance. Try your Free Trial here.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Would it be possible to use Graphics32 in C++ Builder?
Your best bet would be to try it and see. Most Delphi libraries work C++Builder, but it can depend on the version.
I got it to work and used it up to C++Builder XE, but can’t get it to install with newer versions, despite trying all the options/suggestions I could find on-line. Would be great it we could!
We’ll see what we can do. If someone has got it working with more recent versions of RAD Studio they’re welcome to comment here too.
Is it cross-platform?
It is Windows-only. There is a version which works with CrossVCL which you can find here: https://github.com/eugenekryukov/graphics32.
There are also some efforts to produce an FMX version which would then hopefully make it cross-platform but as far as I can tell this effort is currently stalled.
Hello,
There seems to be a problem of compatibility with the new DELPHI 12 Athens version . The sources that worked fine with DELPHI 11 and GRAPHICS32 produce an avalanche of unaccountable mistakes when compiling with DELPHI 12 and GRAPHICS32 . I think an update is missing with GRAPHICS32. Am I right ? Is there a way to solve that problem ?