Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sun Apr 20, 2014 10:09 am

Hi,
I am currently evaluating your software and the first impression is very good.
In my application I need to fill a triangle with a color where the color is depending on the x and y value within the triangle.
Here is my code where the triangle is filled with one color. It works fine.
Dim points(2) As Point
points(0) = New Point(200, 200) : points(1) = New Point(400, 300) : points(2) = New Point(300, 100)
Dim path As New PdfPath()
path.AddLine(points(0), points(1)) : path.AddLine(points(1), points(2)) : path.AddLine(points(2), points(0))
Dim pen As New PdfPen(Color.DeepSkyBlue, 0.02F)
Dim brush1 As PdfBrush = New PdfSolidBrush(Color.CadetBlue)
path.FillMode = PdfFillMode.Alternate
page.Canvas.DrawPath(pen, brush1, path)

I already studied LineairGradient and RadialGradient Brush but that does not bring the solution.

To give you an example, I already did some math:
For the above mentioned triangle, a reference to an RGB-color can be made with the following formula:
Z = 0.008125 * X - 0.00625 * Y + 0.625
E.g. Z = 1 then PdfSolidBrush(Color.FromArgb((CInt((CByte(255)))), (CInt((CByte(192)))), (CInt((CByte(128)))))), etc..
I can make that translation table myself.

So the question is:
Is it possible to fill a rectangle based on the x and y position in that rectangle.
Should I work with e.g. "dots"?
Please advise.

Kind regards
Andre

cossee
 
Posts: 2
Joined: Tue Apr 15, 2014 5:01 pm

Mon Apr 21, 2014 9:15 am

Hello,

Thanks for evaluating our product.

Sorry that there is no better method than the way to fill the rectangle by dots.

If there are any questions, welcome to get it back to us.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.PDF