Recent

Author Topic: BGRAbitmap + gradient Polygon (Rectbox or Ellipse)  (Read 307 times)

SirTwist

  • New Member
  • *
  • Posts: 20
BGRAbitmap + gradient Polygon (Rectbox or Ellipse)
« on: August 15, 2020, 01:39:37 pm »
Dear community,

I am rather new with BGRAbitmap, but not with programming at all - using Delphi since 1.0

I want to draw a filled rectangle or ellipse with a gradient fill, e.g. from the lightblue topleft corner to a darkblue right bottom corner. I went through the tutorial within the Lazarus wiki, and tried some other ressources, but I didn't get satisfying results. The image attached shows what I do like to achieve.

I found in some source code this:
Code: Pascal  [Select][+][-]
  1. grad := TBGRAGradientScanner.Create(BGRA(255,255,0),BGRA(255,0,0),gtLinear,PointF(0,0),PointF(400, 200),True,True);
and used it in:
Code: Pascal  [Select][+][-]
  1. aBMP.DrawPolygonAntialias(pxls, grad, 5);
But this draws only the outline in different colours, without any infill. And I cannot find any DrawPolygon where I can pas a second (or the same) grad for the background colour.

Is there anyone who can help here or can give me source code sniplet? Thank you very much!

Kind regards,
Sir Twist

Handoko

  • Hero Member
  • *****
  • Posts: 3868
  • My goal: build my own game engine using Lazarus
Re: BGRAbitmap + gradient Polygon (Rectbox or Ellipse)
« Reply #1 on: August 15, 2020, 02:41:09 pm »
I haven't tried but I believe that can be done using mask.
https://wiki.freepascal.org/BGRABitmap_tutorial_5

First, you paint the gradient on a TBGRABitmap and generate the mask. Then combine them together.

winni

  • Hero Member
  • *****
  • Posts: 1908
Re: BGRAbitmap + gradient Polygon (Rectbox or Ellipse)
« Reply #2 on: August 15, 2020, 03:18:02 pm »
Hi!

Handokos solution is one way.

The other way is

Code: Pascal  [Select][+][-]
  1. aBMP.FillPolyAntialias(pxls, grad);
  2. aBMP.DrawPolygonAntialias(pxls, cssBlack, 5,BGRApixelTransparent);
  3.  

Winni

SirTwist

  • New Member
  • *
  • Posts: 20
Re: BGRAbitmap + gradient Polygon (Rectbox or Ellipse)
« Reply #3 on: August 18, 2020, 08:50:19 pm »
Thank you both! I had a deeper look at the Tutorial, and got the way via a seperate mask working.
Winni, I will try your way also, later.
Thank you!

 

TinyPortal © 2005-2018