internal static BarcodeSurface CreateFullAsciiCode39(Rectangle rect, Surface source, string text, ColorBgra primaryColor, ColorBgra secondaryColor) { if (!ValidateFullAsciiCode39(text)) { BarcodeSurface barcode = new BarcodeSurface(rect); return(barcode); } return(Create(rect, source, text, primaryColor, secondaryColor)); }
internal static BarcodeSurface Create(Rectangle rect, Surface source, string text, ColorBgra primaryColor, ColorBgra secondaryColor) { BarcodeSurface barcode = new BarcodeSurface(rect); if (!Validate(text)) { return(barcode); } string encodedText = Encode(text); int barWidth = (int)Math.Floor((double)barcode.Width / encodedText.Length); int halfBarHeight = (int)Math.Floor((double)barcode.Height / 2.0); int currentHeight = 0; for (int y = rect.Top; y < rect.Bottom; y++) { int loc = 0; int step = 0; for (int x = rect.Left; x < rect.Right; x++) { if (loc < encodedText.Length && barWidth > 0 && halfBarHeight > 0) { if (encodedText[loc] == 'w' || (encodedText[loc] == 'b' && currentHeight <= halfBarHeight)) { barcode[x, y] = secondaryColor; } else if (encodedText[loc] == 'B' || (encodedText[loc] == 'b' && currentHeight > halfBarHeight)) { barcode[x, y] = primaryColor; } else { barcode[x, y] = source[x, y]; } step++; if (step % barWidth == 0) { loc++; } } else { barcode[x, y] = source[x, y]; } } currentHeight++; } return(barcode); }
public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length) { // Set the text to encode and the encoding type String toEncode = ((BarcodeConfigToken)parameters).TextToEncode; int encoding = ((BarcodeConfigToken)parameters).EncodingType; BarcodeSurface barcode = null; Rectangle selection = this.EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt(); ColorBgra primary = this.EnvironmentParameters.PrimaryColor; ColorBgra secondary = this.EnvironmentParameters.SecondaryColor; if (encoding == Barcode.CODE_39) { Code39 code39 = new Code39(); barcode = code39.CreateCode39(selection, srcArgs.Surface, toEncode, primary, secondary); } else if (encoding == Barcode.CODE_39_MOD_43) { Code39 code39 = new Code39(); barcode = code39.CreateCode39mod43(selection, srcArgs.Surface, toEncode, primary, secondary); } else if (encoding == Barcode.FULL_ASCII_CODE_39) { Code39 code39 = new Code39(); barcode = code39.CreateFullAsciiCode39(selection, srcArgs.Surface, toEncode, primary, secondary); } else if (encoding == Barcode.POSTNET) { Postnet postnet = new Postnet(); barcode = postnet.Create(selection, srcArgs.Surface, toEncode, primary, secondary); } for (int i = startIndex; i < startIndex + length; ++i) { Rectangle rect = rois[i]; for (int y = rect.Top; y < rect.Bottom; ++y) { for (int x = rect.Left; x < rect.Right; ++x) { dstArgs.Surface[x, y] = barcode[x, y]; } } } }
public BarcodeSurface Create(Rectangle rect, Surface source, String text, ColorBgra primaryColor, ColorBgra secondaryColor) { BarcodeSurface barcode = new BarcodeSurface(rect); String encodedText = this.Encode(text); int barWidth = (int)System.Math.Floor((double)barcode.Width / encodedText.Length); int halfBarHeight = (int)System.Math.Floor((double)barcode.Height / 2.0); int currentHeight = 0; for (int y = rect.Top; y < rect.Bottom; y++) { int loc = 0; int step = 0; for (int x = rect.Left; x < rect.Right; x++) { if (loc < encodedText.Length && barWidth > 0 && halfBarHeight > 0) { if (encodedText[loc] == 'w' || (encodedText[loc] == 'b' && currentHeight <= halfBarHeight)) { barcode[x, y] = secondaryColor; } else if (encodedText[loc] == 'B' || (encodedText[loc] == 'b' && currentHeight > halfBarHeight)) { barcode[x, y] = primaryColor; } else { barcode[x,y] = source[x,y]; } step++; if (step % barWidth == 0) loc++; } else { barcode[x, y] = source[x, y]; } } currentHeight++; } return barcode; }
private BarcodeSurface Create(Rectangle rect, Surface source, String text, ColorBgra primaryColor, ColorBgra secondaryColor) { BarcodeSurface barcode = new BarcodeSurface(rect); String encodedText = this.Encode(text); int barWidth = (int)System.Math.Floor((double)barcode.Width / encodedText.Length); for (int y = rect.Top; y < rect.Bottom; y++) { int loc = 0; int step = 0; for (int x = rect.Left; x < rect.Right; x++) { if (loc < encodedText.Length && barWidth > 0) { if (encodedText[loc] == 'w') { barcode[x, y] = secondaryColor; } else if (encodedText[loc] == 'b') { barcode[x, y] = primaryColor; } else { barcode[x, y] = source[x, y]; } step++; if (step % barWidth == 0) { loc++; } } else { barcode[x, y] = source[x, y]; } } } return(barcode); }
internal static BarcodeSurface Create(Rectangle rect, Surface source, string text, ColorBgra primaryColor, ColorBgra secondaryColor) { BarcodeSurface barcode = new BarcodeSurface(rect); if (!Validate(text)) { return(barcode); } imageScale = rect.Width / 120; if (imageScale < 1 || rect.Height < (rect.Width * 1 / 6)) { return(barcode); } barCodeHeight = (int)(rect.Height / imageScale); imageWidth = 120; imageWidth = Convert.ToInt32(imageWidth * imageScale); newBitmap = new Bitmap(imageWidth, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); g = Graphics.FromImage(newBitmap); g.ScaleTransform(imageScale, imageScale); Rectangle newRec = new Rectangle(0, 0, imageWidth, rect.Height); g.FillRectangle(new SolidBrush(secondaryColor), newRec); placeMarker = 0; text = text.Substring(0, 11) + GetCheckSum(text).ToString(); int wholeSet = 0; for (wholeSet = 1; wholeSet <= Convert.ToInt32(text.Length); wholeSet++) { int currentASCII = Convert.ToChar(text.Substring(wholeSet - 1, 1)) - 48; if (wholeSet == 1) { DrawSet(UPCABegin, placeMarker, barCodeHeight, 0, primaryColor, secondaryColor); DrawSet(UPCALeft[currentASCII], placeMarker, barCodeHeight, 0, primaryColor, secondaryColor); } else if (wholeSet <= 5) { DrawSet(UPCALeft[currentASCII], placeMarker, barCodeHeight, 6, primaryColor, secondaryColor); } else if (wholeSet == 6) { DrawSet(UPCALeft[currentASCII], placeMarker, barCodeHeight, 6, primaryColor, secondaryColor); DrawSet(UPCAMiddle, placeMarker, barCodeHeight, 0, primaryColor, secondaryColor); } else if (wholeSet <= 11) { DrawSet(UPCARight[currentASCII], placeMarker, barCodeHeight, 6, primaryColor, secondaryColor); } else if (wholeSet == 12) { DrawSet(UPCARight[currentASCII], placeMarker, barCodeHeight, 0, primaryColor, secondaryColor); DrawSet(UPCAEnd, placeMarker, barCodeHeight, 0, primaryColor, secondaryColor); } } Font font = new Font("Courier New, Bold", 9); try { SolidBrush textBrush = new SolidBrush(primaryColor); float yPoint = barCodeHeight - 13; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; g.DrawString(text.Substring(0, 1), font, textBrush, new PointF(0, yPoint)); g.DrawString(text.Substring(1, 5), font, textBrush, new PointF(22, yPoint)); g.DrawString(text.Substring(6, 5), font, textBrush, new PointF(60, yPoint)); g.DrawString(text.Substring(11, 1), font, textBrush, new PointF(108, yPoint)); } finally { font.Dispose(); } Surface upcaSurface = Surface.CopyFromBitmap(newBitmap); newBitmap.Dispose(); for (int y = rect.Top; y < rect.Bottom; ++y) { for (int x = rect.Left; x < rect.Right; ++x) { barcode[x, y] = upcaSurface.GetBilinearSample(x - rect.Left, y - rect.Top); } } return(barcode); }