PDFsharp & MigraDoc Foundation http://forum.pdfsharp.de/ |
|
Using Transparency in GradientBrush http://forum.pdfsharp.de/viewtopic.php?f=2&t=4500 |
Page 1 of 1 |
Author: | pablovlc [ Thu Nov 02, 2023 11:34 pm ] |
Post subject: | Using Transparency in GradientBrush |
Hello guys, thank you for an awesome PDF lib, really appreciated. As for this bugreport: The following code produces a solid red rectangle, without gradient to transparent as I hoped for. The code can be run as console app (copy paste console app), .net6.0, pdfsharp prev 4. Checked in chrome, edge and sumatraPdf. Am I missing something? Code: using PdfSharp.Drawing;
using PdfSharp.Pdf; using System.IO; public static void DrawGradientRectangle(string filePath) { using (PdfDocument document = new PdfDocument()) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XRect rect = new XRect(50, 50, 250, 100); // x, y, width, height // Create a red to transparent gradient brush XLinearGradientBrush brush = new XLinearGradientBrush( rect, XColor.FromArgb(255, 255, 0, 0), // Solid Red XColor.FromArgb(0, 255, 0, 0), // Transparent Red XLinearGradientMode.Horizontal ); // Draw the rectangle with the gradient brush gfx.DrawRectangle(brush, rect); // Save the document document.Save(filePath); } } // Call the function and provide the path to save the PDF DrawGradientRectangle("GradientRectangle.pdf"); |
Author: | Thomas Hoevel [ Tue Nov 07, 2023 1:33 pm ] |
Post subject: | Re: Using Transparency in GradientBrush |
pablovlc wrote: The following code produces a solid red rectangle, without gradient to transparent as I hoped for. Are you using the WPF build?
|
Author: | pablovlc [ Fri Nov 10, 2023 5:11 pm ] |
Post subject: | Re: Using Transparency in GradientBrush |
Thank you for looking into this issue. Version used: Dotnet 6 core preview 4 on windows. I upgraded to Version 6 stable release, again core. The result is the same. |
Author: | Thomas Hoevel [ Mon Nov 13, 2023 10:53 am ] |
Post subject: | Re: Using Transparency in GradientBrush |
As far as I can tell, this is not a bug. XColor is the interface and it supports transparency. Gradient fills in PDF seem to work with solid colors only, so transparency gets lost at this stage. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |