diff --git a/RdlCri/BarCodeEAN13.cs b/RdlCri/BarCodeEAN13.cs index 7dd1e5d2..bb4e5d6d 100644 --- a/RdlCri/BarCodeEAN13.cs +++ b/RdlCri/BarCodeEAN13.cs @@ -139,14 +139,14 @@ internal void DrawImage(Draw2.Bitmap bm, string upcode) // Fill in the background with white g.FillRectangle(Draw2.Brushes.White, 0, 0, bm.Width, bm.Height); - // Draw the bars - int barCount = LeftQuietZoneModules; + // Draw the bars - start from 0 to align left + int barCount = 0; foreach (char bar in barPattern) { if (bar == '1') { - float bh = ((barCount > ModulesToManufacturingStart && barCount < ModulesToManufacturingEnd) || - (barCount > ModulesToProductStart && barCount < ModulesToProductEnd)) + float bh = ((barCount > GuardModules && barCount < GuardModules + ManufacturingModules) || + (barCount > GuardModules + ManufacturingModules + CenterBarModules && barCount < GuardModules + ManufacturingModules + CenterBarModules + ProductModules)) ? barHeight - fontHeightMM : barHeight; @@ -159,22 +159,22 @@ internal void DrawImage(Draw2.Bitmap bm, string upcode) // Draw the human readable portion of the barcode using var f = new Draw2.Font("Arial", fontHeight); - // Draw the left guard text (i.e. 2nd digit of the NumberSystem) + // Draw the left guard text (i.e. 1st digit of the NumberSystem) string wc = upcode.Substring(0, 1); g.DrawString(wc, f, Draw2.Brushes.Black, - new Draw2.PointF(barWidth * LeftQuietZoneModules - g.MeasureString(wc, f).Width, + new Draw2.PointF(0, barHeight - fontHeightMM)); // Draw the manufacturing digits wc = upcode.Substring(1, 6); g.DrawString(wc, f, Draw2.Brushes.Black, - new Draw2.PointF(barWidth * ModulesToManufacturingEnd - g.MeasureString(wc, f).Width, + new Draw2.PointF(barWidth * (GuardModules + ManufacturingModules) - g.MeasureString(wc, f).Width, barHeight - fontHeightMM)); // Draw the product code + the checksum digit wc = upcode.Substring(7, 5) + CheckSum(upcode).ToString(); g.DrawString(wc, f, Draw2.Brushes.Black, - new Draw2.PointF(barWidth * ModulesToProductEnd - g.MeasureString(wc, f).Width, + new Draw2.PointF(barWidth * (GuardModules + ManufacturingModules + CenterBarModules + ProductModules) - g.MeasureString(wc, f).Width, barHeight - fontHeightMM)); } diff --git a/RdlCri/BarCodeITF14.cs b/RdlCri/BarCodeITF14.cs index 541a4479..ee5aec1c 100644 --- a/RdlCri/BarCodeITF14.cs +++ b/RdlCri/BarCodeITF14.cs @@ -52,7 +52,15 @@ private void InternalDraw(ref Bitmap bm, string value) var img = Image.FromStream(v.Encode().AsStream()); - bm = new Bitmap(img); + // Draw the barcode aligned to the left instead of replacing the bitmap + using (var g = Graphics.FromImage(bm)) + { + // Fill background with white + g.FillRectangle(Brushes.White, 0, 0, bm.Width, bm.Height); + + // Draw the barcode aligned to the left (top-left corner at 0, 0) + g.DrawImage(img, 0, 0); + } } public string GetCustomReportItemXml() diff --git a/RdlCri/ZxingBarcodes.cs b/RdlCri/ZxingBarcodes.cs index 896091f5..6f321c65 100644 --- a/RdlCri/ZxingBarcodes.cs +++ b/RdlCri/ZxingBarcodes.cs @@ -82,7 +82,13 @@ internal void DrawImage(ref Draw2.Bitmap bm, string qrcode) // The provider has already been registered. } - bm = writer.Write(qrcode); + var barcodeBitmap = writer.Write(qrcode); + + // Fill background with white + g.FillRectangle(Draw2.Brushes.White, 0, 0, bm.Width, bm.Height); + + // Draw the barcode aligned to the left (top-left corner at 0, 0) + g.DrawImage(barcodeBitmap, 0, 0); } ///