Please refer to follow code:
PdfPen pn = new PdfPen(Color.Red, 10); RectangleF rec=new RectangleF(0, 0, 100, 50); graphics.DrawRectangle(pn, rec);
The result is:
As you can see. The thickness size is not the same. some sides wide from other.
How can get it write?
Hi Matanya,
We were able to reproduce the reported issue with the provided details on our end, and currently, we are analyzing it. We will provide further details on July 5, 2024.
Regards,
Jeyalakshmi T
I realize, that the problem disappeared if I set:
RectangleF rec=new RectangleF(3, 3, 100, 50);
Instead:
RectangleF rec=new RectangleF(0, 0, 100, 50);
It's seem like that point 0,0 is outside the view??
Hi Matanya,
Upon further analysis, we observed that the rectangle's rendered size is affected by the pen width when its location is initialized at (0,0). This behavior is consistent with GDI+. To achieve equal widths on all sides, you can adjust the rectangle's location accordingly.
GDI+
| Result |
System.Drawing.Bitmap bitmap = new Bitmap(300, 300); System.Drawing.Graphics gr = Graphics.FromImage(bitmap); Pen pen = new Pen(Color.Red, 10); gr.DrawRectangle(pen, new Rectangle(0, 0, 100, 50)); gr.Dispose(); bitmap.Save("Rectangle.png"); |
|
Regards,
Jeyalakshmi T
Did your PDF Lib write to GDI+, And then converting to PDF? What happened on Linux?
(I do expect that the result PDF is not the same across all platforms)
Hi Matanya,
On further analysis,we have internally draw path for the rectangle like GDI+ in all platforms.This issue occurs while assigning the location (0,0) clipregion cut the width of the upperside and left side of the rectangle Because the pen width is 10, the sides of the rectangle are drawn 10 points wide, such that 2 points are drawn on the boundary itself, 4 points are drawn on the inside, and 4 points are drawn on the outside.
you can adjust the location by highlighted line in below image
Regards,
Raashith Ahamed S
Thanks. It's interest me if those info documented some ware?
I try understand, please refer to more Q:
A:
This behavior is only for Draw with Pen. All Draw without Pen as parameter, not effected.
For example, Draw Rectangle with Brushes (only). That's true?
B:
You wrote:
" Because the pen width is 10, the sides of the rectangle are drawn 10 points wide, such that 2 points are drawn on the boundary itself, 4 points are drawn on the inside, and 4 points are drawn on the outside. "
What mean boundary itself? (the expression: pn.Width/2 = 5 not 4)
C:
What meaning have to Pen and Brushes regard to DrawString?
DrawString(string s, PdfFont font, PdfPen pen, PdfBrush brush, PointF point)
Hi Matanya,
This behavior is only for Draw with Pen. All Draw without Pen as parameter, not effected. For example, Draw Rectangle with Brushes (only). That's true? | Yes, while drawing the rectangle using a brush, the brush fills the rectangle, so it does not draw like a pen. |
You wrote: " Because the pen width is 10, the sides of the rectangle are drawn 10 points wide, such that 2 points are drawn on the boundary itself, 4 points are drawn on the inside, and 4 points are drawn on the outside. " What mean boundary itself? (the expression: pn.Width/2 = 5 not 4) | Boundary itself means the location of the rectangle. If the location is 0,0, the 2 points are drawn on the boundary, 4 points are drawn inside the rectangle, and 4 points are outside the rectangle. While drawing 4 points outside the rectangle for the location (0,0), the rectangle gets cut off outside of the rectangle.
For more information, How to: Use a Pen to Draw Rectangles - Windows Forms .NET Framework | Microsoft Learn
The expression is only to adjust the location to cut off the rectangle for that purpose only. |
What meaning have to Pen and Brushes regard to DrawString? | Pen: Used to outline the text. This is particularly useful if you want to draw text with a border around each character. Brush: Used to fill the text with a solid color or gradient. |
Regards,
Jeyalakshmi T