private BinChain GenerateBinary_EAN13(string barcode) { BinChain chain = new BinChain(); chain.data = new int[200]; int nzeros_init = 12 - barcode.Length; string barcodefull = ""; for (int i = 0; i < nzeros_init; i++) { barcodefull = barcodefull + "0"; } barcodefull = barcodefull + barcode; //ckecksum must be applied barcodefull = UTILITIES.appendChecksum(barcodefull); int[] isLnoG = new int[6]; if (barcodefull[0] == '0'){ int[] isLnoGaux = new int[6]{1 , 1 , 1 , 1 , 1 , 1}; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '1') { int[] isLnoGaux = new int[6] { 1, 1, 0, 1, 0, 0 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '2') { int[] isLnoGaux = new int[6] { 1, 1, 0, 0, 1, 0 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '3') { int[] isLnoGaux = new int[6] { 1, 1, 0, 0, 0, 1 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '4') { int[] isLnoGaux = new int[6] { 1, 0, 1, 1, 0, 0 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '5') { int[] isLnoGaux = new int[6] { 1, 0, 0, 1, 1, 0 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '6') { int[] isLnoGaux = new int[6] { 1, 0, 0, 0, 1, 1 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '7') { int[] isLnoGaux = new int[6] { 1, 0, 1, 0, 1, 0 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '8') { int[] isLnoGaux = new int[6] { 1, 0, 1, 0, 0, 1 }; Array.Copy(isLnoGaux, isLnoG, 6); } else if (barcodefull[0] == '9') { int[] isLnoGaux = new int[6] { 1, 0, 0, 1, 0, 1 }; Array.Copy(isLnoGaux, isLnoG, 6); } int[] blank = new int[6] { 0, 0, 0, 0, 0, 0 }; int[] D = new int[3] { 1, 0, 1 }; int[] M = new int[5] { 0, 1, 0, 1, 0 }; int index = 0; for (int i = 0; i < 6; i++) { chain.data[index] = blank[i]; index++; } for (int i = 0; i < 3; i++) { chain.data[index] = D[i]; index++; } for (int i = 1; i < 7; i++) { char c = barcodefull.ElementAt(i); int[] data; if (isLnoG[i - 1] == 1) { if (c == '0') { data = new int[] { 0, 0, 0, 1, 1, 0, 1 }; } else if (c == '1') { data = new int[7] { 0, 0, 1, 1, 0, 0, 1 }; } else if (c == '2') { data = new int[7] { 0, 0, 1, 0, 0, 1, 1 }; } else if (c == '3') { data = new int[7] { 0, 1, 1, 1, 1, 0, 1 }; } else if (c == '4') { data = new int[7] { 0, 1, 0, 0, 0, 1, 1 }; } else if (c == '5') { data = new int[7] { 0, 1, 1, 0, 0, 0, 1 }; } else if (c == '6') { data = new int[7] { 0, 1, 0, 1, 1, 1, 1 }; } else if (c == '7') { data = new int[7] { 0, 1, 1, 1, 0, 1, 1 }; } else if (c == '8') { data = new int[7] { 0, 1, 1, 0, 1, 1, 1 }; } else { data = new int[7] { 0, 0, 0, 1, 0, 1, 1 }; } } else { if (c == '0') { data = new int[] { 0, 1, 0, 0, 1, 1, 1 }; } else if (c == '1') { data = new int[7] { 0, 1, 1, 0, 0, 1, 1 }; } else if (c == '2') { data = new int[7] { 0, 0, 1, 1, 0, 1, 1 }; } else if (c == '3') { data = new int[7] { 0, 1, 0, 0, 0, 0, 1 }; } else if (c == '4') { data = new int[7] { 0, 0, 1, 1, 1, 0, 1 }; } else if (c == '5') { data = new int[7] { 0, 1, 1, 1, 0, 0, 1 }; } else if (c == '6') { data = new int[7] { 0, 0, 0, 0, 1, 0, 1 }; } else if (c == '7') { data = new int[7] { 0, 0, 1, 0, 0, 0, 1 }; } else if (c == '8') { data = new int[7] { 0, 0, 0, 1, 0, 0, 1 }; } else { data = new int[7] { 0, 0, 1, 0, 1, 1, 1 }; } } for (int m = 0; m < 7; m++) { chain.data[index] = data[m]; index++; } } for (int i = 0; i < 5; i++) { chain.data[index] = M[i]; index++; } for (int i = 7; i < 13; i++) { char c = barcodefull.ElementAt(i); int[] data; if (c == '0') { data = new int[7] { 1, 1, 1, 0, 0, 1, 0 }; } else if (c == '1') { data = new int[7] { 1, 1, 0, 0, 1, 1, 0 }; } else if (c == '2') { data = new int[7] { 1, 1, 0, 1, 1, 0, 0 }; } else if (c == '3') { data = new int[7] { 1, 0, 0, 0, 0, 1, 0 }; } else if (c == '4') { data = new int[7] { 1, 0, 1, 1, 1, 0, 0 }; } else if (c == '5') { data = new int[7] { 1, 0, 0, 1, 1, 1, 0 }; } else if (c == '6') { data = new int[7] { 1, 0, 1, 0, 0, 0, 0 }; } else if (c == '7') { data = new int[7] { 1, 0, 0, 0, 1, 0, 0 }; } else if (c == '8') { data = new int[7] { 1, 0, 0, 1, 0, 0, 0 }; } else { data = new int[7] { 1, 1, 1, 0, 1, 0, 0 }; } for (int m = 0; m < 7; m++) { chain.data[index] = data[m]; index++; } } for (int i = 0; i < 3; i++) { chain.data[index] = D[i]; index++; } for (int i = 0; i < 6; i++) { chain.data[index] = blank[i]; index++; } chain.size = index; return chain; }
private void SendBinaryImage(BinChain chain) { int size = chain.size; int lineWidth = 2; int totalheight = 110; // alsada en pixels System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(size*lineWidth, totalheight); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); System.Drawing.Drawing2D.GraphicsState gs = g.Save(); g.PageUnit = System.Drawing.GraphicsUnit.Pixel; g.PageScale = 1; System.Drawing.SolidBrush brushblack = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.SolidBrush brushwhite = new System.Drawing.SolidBrush(System.Drawing.Color.White); System.Drawing.Color black = System.Drawing.Color.White; System.Drawing.Color white = System.Drawing.Color.White; int xPosition = 0; for (int i = 0; i < size; i++) { if (chain.data[i] == 1) { g.FillRectangle(brushblack, xPosition, 0, lineWidth, totalheight); /*for (int xi = xPosition; xi < xPosition + lineWidth; xi++) { for (int yi = 0; yi < totalheight; yi++) { // bmp.SetPixel(xi, yi, black); } }*/ } else { g.FillRectangle(brushwhite, xPosition, 0, lineWidth, totalheight); /*for (int xi = xPosition; xi < xPosition + lineWidth; xi++) { for (int yi = 0; yi < totalheight; yi++) { // bmp.SetPixel(xi, yi, white); } }*/ } xPosition += lineWidth; } g.Restore(gs); g.Dispose(); using (MemoryStream ms = new MemoryStream()) { bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); Context.Response.ContentType = "image/png"; ms.WriteTo(Context.Response.OutputStream); } //UTILITIES.Send_Bitmap_As_Response(bmp, Response); }
private BinChain GenerateBinary_UPC_A(long barcodenum) { BinChain chain = new BinChain(); chain.data = new int[200]; string barcode = barcodenum.ToString(); int nzeros_init = 12 - barcode.Length; string barcodefull = ""; for (int i = 0; i < nzeros_init; i++) { barcodefull = barcodefull + "0"; } barcodefull = barcodefull + barcode; int[] blank = new int[6] { 0, 0, 0, 0, 0, 0 }; int[] D = new int[3] { 1, 0, 1 }; int[] M = new int[5] { 0, 1, 0, 1, 0 }; int index = 0; for (int i = 0; i < 6; i++) { chain.data[index] = blank[i]; index++; } for (int i = 0; i < 3; i++) { chain.data[index] = D[i]; index++; } for (int i = 0; i < 6; i++) { char c = barcodefull.ElementAt(i); int[] data; if (c == '0') { data = new int[] { 0, 0, 0, 1, 1, 0, 1 }; } else if (c == '1') { data = new int[7] { 0, 0, 1, 1, 0, 0, 1 }; } else if (c == '2') { data = new int[7] { 0, 0, 1, 0, 0, 1, 1 }; } else if (c == '3') { data = new int[7] { 0, 1, 1, 1, 1, 0, 1 }; } else if (c == '4') { data = new int[7] { 0, 1, 0, 0, 0, 1, 1 }; } else if (c == '5') { data = new int[7] { 0, 1, 1, 0, 0, 0, 1 }; } else if (c == '6') { data = new int[7] { 0, 1, 0, 1, 1, 1, 1 }; } else if (c == '7') { data = new int[7] { 0, 1, 1, 1, 0, 1, 1 }; } else if (c == '8') { data = new int[7] { 0, 1, 1, 0, 1, 1, 1 }; } else { data = new int[7] { 0, 0, 0, 1, 0, 1, 1 }; } for (int m = 0; m < 7; m++) { chain.data[index] = data[m]; index++; } } for (int i = 0; i < 5; i++) { chain.data[index] = M[i]; index++; } for (int i = 6; i < 12; i++) { char c = barcodefull.ElementAt(i); int[] data; if (c == '0') { data = new int[7] { 1, 1, 1, 0, 0, 1, 0 }; } else if (c == '1') { data = new int[7] { 1, 1, 0, 0, 1, 1, 0 }; } else if (c == '2') { data = new int[7] { 1, 1, 0, 1, 1, 0, 0 }; } else if (c == '3') { data = new int[7] { 1, 0, 0, 0, 0, 1, 0 }; } else if (c == '4') { data = new int[7] { 1, 0, 1, 1, 1, 0, 0 }; } else if (c == '5') { data = new int[7] { 1, 0, 0, 1, 1, 1, 0 }; } else if (c == '6') { data = new int[7] { 1, 0, 1, 0, 0, 0, 0 }; } else if (c == '7') { data = new int[7] { 1, 0, 0, 0, 1, 0, 0 }; } else if (c == '8') { data = new int[7] { 1, 0, 0, 1, 0, 0, 0 }; } else { data = new int[7] { 1, 1, 1, 0, 1, 0, 0 }; } for (int m = 0; m < 7; m++) { chain.data[index] = data[m]; index++; } } for (int i = 0; i < 3; i++) { chain.data[index] = D[i]; index++; } for (int i = 0; i < 6; i++) { chain.data[index] = blank[i]; index++; } chain.size = index; return chain; }