Fix EAN-13 barcode rendering quality for better scanning and readability #248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The EAN-13 barcode implementation had critical quality issues that prevented reliable use:
These issues were reported in [issue #XXX] with scanned images showing the poor quality output.
Root Cause
The original implementation in
BarCodeEAN13.csusedGraphicsUnit.Millimeterfor rendering, which caused several problems:Solution
This PR implements a pixel-perfect rendering approach:
1. Pixel-Based Rendering
Changed from
GraphicsUnit.MillimetertoGraphicsUnit.Pixelfor all drawing operations, ensuring precise control over pixel placement.2. Graphics Quality Settings
Added explicit quality settings to prevent anti-aliasing on bars while preserving it for text:
3. Pixel Alignment
Round all bar positions and widths to whole pixels to eliminate fractional positioning:
4. Improved Text Rendering
TextRenderingHint.AntiAliasfor smooth, readable textGraphicsUnit.Pixelfor consistent sizing5. Proper Unit Conversion
Use the existing
PixelConversionsutility to properly convert millimeters to pixels based on the graphics context DPI.Testing
Added comprehensive test suite in
BarCodeEAN13Tests.cs:Impact
Visual Comparison
Before: Bars had anti-aliased edges (gray pixels at boundaries), text was too small
After: Sharp black/white bar boundaries perfect for scanning, readable text with minimum 8-pixel font
The changes ensure that:
Files Changed
RdlCri/BarCodeEAN13.cs- Core rendering improvements (64 lines modified)ReportTests/BarCodeEAN13Tests.cs- New comprehensive test suite (148 lines added)Total: 2 files changed, 191 insertions(+), 21 deletions(-)
Original prompt
Fixes #182
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.