/// <summary> /// Generates a Standard (Industrial) 2 of 5 barcode of a specified size, using the data that has been set previously by its corresponding /// encoder. /// </summary> /// <param name="size">The size of the barcode to return.</param> /// <returns>A bitmap of the barcode, of the specified size.</returns> /// <exception cref="System.ArgumentException">The specified size is invalid.</exception> /// <exception cref="System.InvalidOperationException">The data that is to be encoded has not been set yet.</exception> public override Bitmap GenerateBarcode(Size size) { if (data == null) { throw new InvalidOperationException("The data for the generator has not been set."); } if (!Sizer.IsValidSize(size)) { throw new ArgumentException("The specified size is not valid."); } EncodeData(); Bitmap bm = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppRgb); Graphics g = Graphics.FromImage(bm); int module, guard; module = ((S2of5Sizer)Sizer).ModuleWidth; guard = ((S2of5Sizer)Sizer).GuardWidth; S2of5Sizer sSizer = (S2of5Sizer)Sizer; if (sSizer.TopWidth != 0) { g.FillRectangle(Brushes.White, Rectangle.FromLTRB(sSizer.SideBrace, sSizer.TopWidth, size.Width - sSizer.SideBrace, size.Height - sSizer.BottomWidth)); } else { g.FillRectangle(Brushes.White, 0, 0, size.Width, size.Height); } int pos = guard; for (int i = 0; i < encodedData.Length; i++) { if (encodedData[i]) { g.FillRectangle(Brushes.Black, pos, 0, module, size.Height); } pos += module; } if (sSizer.FontHeight != 0) { string text = ""; foreach (byte b in data) { text += b.ToString(); } g.FillRectangle(Brushes.White, Rectangle.FromLTRB(0, size.Height - sSizer.FontHeightAddon, size.Width, size.Height)); g.DrawString(text, FontHolder.GenerateFont(sSizer.FontHeight), Brushes.Black, Rectangle.FromLTRB(0, size.Height - sSizer.FontHeightAddon, size.Width, size.Height), FontHolder.CenterJustify); } g.Dispose(); return(bm); }
/// <summary> /// Generates a Codabar barcode of a specified size, using the data that has been set previously by its corresponding /// encoder. /// </summary> /// <param name="size">The size of the barcode to return.</param> /// <returns>A bitmap of the barcode, of the specified size.</returns> /// <exception cref="System.ArgumentException">The specified size is invalid.</exception> /// <exception cref="System.InvalidOperationException">The data that is to be encoded has not been set yet.</exception> public override Bitmap GenerateBarcode(Size size) { if (data == null) { throw new InvalidOperationException("The data for the generator has not been set."); } if (!Sizer.IsValidSize(size)) { throw new ArgumentException("The specified size is not valid."); } EncodeData(); Bitmap bm = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppRgb); Graphics g = Graphics.FromImage(bm); g.FillRectangle(Brushes.White, 0, 0, size.Width, size.Height); int module, guard; module = ((CodabarSizer)Sizer).ModuleWidth; guard = ((CodabarSizer)Sizer).GuardWidth; int pos = guard; for (int i = 0; i < encodedData.Length; i++) { if (encodedData[i]) { g.FillRectangle(Brushes.Black, pos, 0, module, size.Height); } pos += module; } if (((CodabarSizer)Sizer).FontHeight != 0) { string text = ""; foreach (byte b in data) { text += "0123456789-$:/.+ABCD"[b]; } Rectangle textArea = Rectangle.FromLTRB(0, size.Height - ((CodabarSizer)Sizer).FontHeightAddon, size.Width, size.Height); g.FillRectangle(Brushes.White, textArea); g.DrawString(text, FontHolder.GenerateFont(((CodabarSizer)Sizer).FontHeight), Brushes.Black, textArea, FontHolder.CenterJustify); } g.Dispose(); return(bm); }