Description
Hi @Tagliatti, first of all, thank you for your library!
I have been using the library for some time, namely for Code128C. I encountered a problem with versions 1.5+, which I already wrote about (Issue #29).
var barcode = new Barcode("660004005000080000221020220529113509", NetBarcode.Type.Code128C, false, 466, 40);
barcode.SaveImageFile(@"C:\Temp\barcode.png", ImageFormat.Png);
Result for version 1.4.5
Result for version 1.6.0
In the latest version barcode lines are rendered as thicker and when I use barcode.GetBase64Image();
the barcode is really corrupted.
I tried to figure out the cause of the problem and found that the problem is in this part of the code:
imageContext.DrawLines(drawingOptions, pen,
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, 0),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, _height - labelHeight)
);
The problem is with ImageSharp method DrawLines. This method will not draw a line in the form of a solid rectangle if the pen width is equal to or greater than 2 :-(
I suggest using the method FillPolygon, and the corresponding code would look like this:
imageContext.FillPolygon(drawingOptions, _foregroundColor,
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, 0),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth + iBarWidth / iBarWidthModifier, 0),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth + iBarWidth / iBarWidthModifier, _height - labelHeight),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, _height - labelHeight));
The variable pen is no longer needed.
And result for modified version 1.6.0 is the same as the one generated by the library version 1.4.5!
What do you think? Wouldn't it work better this way?
Activity