public string EncodeSvgImage(string val, DmtxImageEncoderOptions options)
        {
            DmtxEncode encode = new DmtxEncode();

            encode.ModuleSize     = options.ModuleSize;
            encode.MarginSize     = options.MarginSize;
            encode.SizeIdxRequest = options.SizeIdx;
            encode.Scheme         = options.Scheme;
            byte[] valAsByteArray = Encoding.ASCII.GetBytes(val);
            encode.EncodeDataMatrix(options.ForeColor, options.BackColor, valAsByteArray);
            return(EncodeSvgFile(encode, "", options.ModuleSize, options.MarginSize, options.ForeColor, options.BackColor));
        }
Exemple #2
0
        public bool[,] EncodeRawData(string val, DmtxImageEncoderOptions options)
        {
            DmtxEncode encode = new DmtxEncode
            {
                ModuleSize     = 1,
                MarginSize     = 0,
                SizeIdxRequest = options.SizeIdx,
                Scheme         = options.Scheme
            };

            byte[] valAsByteArray = GetRawDataAndSetEncoding(val, options, encode);

            encode.EncodeDataMatrixRaw(valAsByteArray);

            return(encode.RawData);
        }
Exemple #3
0
        public string EncodeSvgImage(string val, DmtxImageEncoderOptions options)
        {
            DmtxEncode encode = new DmtxEncode
            {
                ModuleSize     = options.ModuleSize,
                MarginSize     = options.MarginSize,
                SizeIdxRequest = options.SizeIdx,
                Scheme         = options.Scheme
            };

            byte[] valAsByteArray = GetRawDataAndSetEncoding(val, options, encode);

            encode.EncodeDataMatrix(options.ForeColor, options.BackColor, valAsByteArray);

            return(EncodeSvgFile(encode, "", options.ModuleSize, options.MarginSize, options.ForeColor, options.BackColor));
        }
        private Bitmap EncodeImage(string val, DmtxImageEncoderOptions options, bool isMosaic)
        {
            DmtxEncode encode = new DmtxEncode();

            encode.ModuleSize     = options.ModuleSize;
            encode.MarginSize     = options.MarginSize;
            encode.Scheme         = options.Scheme;
            encode.SizeIdxRequest = options.SizeIdx;
            byte[] valAsByteArray = Encoding.ASCII.GetBytes(val);
            if (isMosaic)
            {
                encode.EncodeDataMosaic(valAsByteArray);
            }
            else
            {
                encode.EncodeDataMatrix(options.ForeColor, options.BackColor, valAsByteArray);
            }
            return(CopyDataToBitmap(encode.Image.Pxl, encode.Image.Width, encode.Image.Height));
        }
Exemple #5
0
        private Bitmap EncodeImage(string val, DmtxImageEncoderOptions options, bool isMosaic)
        {
            DmtxEncode encode = new DmtxEncode
            {
                ModuleSize     = options.ModuleSize,
                MarginSize     = options.MarginSize,
                SizeIdxRequest = options.SizeIdx
            };

            byte[] valAsByteArray = GetRawDataAndSetEncoding(val, options, encode);
            if (isMosaic)
            {
                encode.EncodeDataMosaic(valAsByteArray);
            }
            else
            {
                encode.EncodeDataMatrix(options.ForeColor, options.BackColor, valAsByteArray);
            }
            return(CopyDataToBitmap(encode.Image.Pxl, encode.Image.Width, encode.Image.Height));
        }
Exemple #6
0
        private static Bitmap EncodeImage(byte[] valAsByteArray, DmtxImageEncoderOptions options, bool isMosaic)
        {
            DmtxEncode encode = new DmtxEncode
            {
                ModuleSize     = options.ModuleSize,
                MarginSize     = options.MarginSize,
                SizeIdxRequest = options.SizeIdx,
                Scheme         = options.Scheme,
            };

            if (isMosaic)
            {
                encode.EncodeDataMosaic(valAsByteArray);
            }
            else
            {
                encode.EncodeDataMatrix(options.ForeColor, options.BackColor, valAsByteArray);
            }
            return(CopyDataToBitmap(encode.Image.Pxl, encode.Image.Width, encode.Image.Height));
        }
Exemple #7
0
        public bool[,] EncodeRawData(string val, DmtxImageEncoderOptions options)
        {
            DmtxEncode encode = new DmtxEncode
            {
                ModuleSize     = 1,
                MarginSize     = 0,
                SizeIdxRequest = options.SizeIdx,
                Scheme         = options.Scheme
            };

            //options.Scheme = DmtxScheme.DmtxSchemeText;
            //encode.Scheme = DmtxScheme.DmtxSchemeText;

            //převod z UTF-8 do Win1250 - kvůli diakritice
            val = Encoding.GetEncoding(1250).GetString(Encoding.GetEncoding("UTF-8").GetBytes(val));

            byte[] valAsByteArray = GetRawDataAndSetEncoding(val, options, encode);

            encode.EncodeDataMatrixRaw(valAsByteArray);

            return(encode.RawData);
        }
        internal string EncodeSvgFile(DmtxEncode enc, string format, int moduleSize, int margin, Color foreColor, Color backColor)
        {
            int  col, row, rowInv;
            int  symbolCols, symbolRows;
            int  width, height, module;
            bool defineOnly = false;
            //byte mosaicRed, mosaicGrn, mosaicBlu;
            string idString     = null;
            string style        = "";
            string outputString = "";

            if (dotFormatProvider == null)
            {
                dotFormatProvider = new NumberFormatInfo();
                dotFormatProvider.NumberDecimalSeparator = ".";
            }

            if (format == "svg:")
            {
                defineOnly = true;
                idString   = format.Substring(4);
            }

            if (string.IsNullOrEmpty(idString))
            {
                idString = "dmtx_0001";
            }

            width  = 2 * enc.MarginSize + (enc.Region.SymbolCols * enc.ModuleSize);
            height = 2 * enc.MarginSize + (enc.Region.SymbolRows * enc.ModuleSize);

            symbolCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolCols, enc.Region.SizeIdx);
            symbolRows = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolRows, enc.Region.SizeIdx);

            /* Print SVG Header */
            if (!defineOnly)
            {
                outputString += string.Format(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
                    "<!-- Created with YellowstonePathology.Business.DataMatrix (http://datamatrixnet.sourceforge.net/) -->\n" +
                    "<svg\n" +
                    "xmlns:svg=\"http://www.w3.org/2000/svg\"\n" +
                    "xmlns=\"http://www.w3.org/2000/svg\"\n" +
                    "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" +
                    "version=\"1.0\"\n" +
                    "width=\"{0}\"\n" +
                    "height=\"{1}\"\n" +
                    "id=\"svg2\">\n" +
                    "<defs>\n" +
                    "<symbol id=\"{2}\">\n" +
                    "    <desc>Layout:{0}x%{1} Symbol:{3}x{4} Data Matrix</desc>\n", width, height, idString, symbolCols, symbolRows);
            }

            if (backColor != Color.White)
            {
                style = string.Format("style=\"fill:#{0}{1}{2};fill-opacity:{3};stroke:none\" ",
                                      backColor.R.ToString("X2"), backColor.G.ToString("X2"), backColor.B.ToString("X2"), ((double)backColor.A / (double)byte.MaxValue).ToString("0.##", dotFormatProvider));
                outputString += string.Format("    <rect width=\"{0}\" height=\"{1}\" x=\"0\" y=\"0\" {2}/>\n",
                                              width, height, style);
                style = "";
            }

            /* Write Data Matrix ON modules */
            for (row = 0; row < enc.Region.SymbolRows; row++)
            {
                rowInv = enc.Region.SymbolRows - row - 1;
                for (col = 0; col < enc.Region.SymbolCols; col++)
                {
                    module = enc.Message.SymbolModuleStatus(enc.Region.SizeIdx, row, col);
                    style  = string.Format("style=\"fill:#{0}{1}{2};fill-opacity:{3};stroke:none\" ",
                                           foreColor.R.ToString("X2"), foreColor.G.ToString("X2"), foreColor.B.ToString("X2"), ((double)foreColor.A / (double)byte.MaxValue).ToString("0.##", dotFormatProvider));

                    if ((module & DmtxConstants.DmtxModuleOn) != 0)
                    {
                        outputString += string.Format("    <rect width=\"{0}\" height=\"{1}\" x=\"{2}\" y=\"{3}\" {4}/>\n",
                                                      moduleSize, moduleSize,
                                                      col * moduleSize + margin,
                                                      rowInv * moduleSize + margin, style);
                    }
                }
            }

            outputString += "  </symbol>\n";

            /* Close SVG document */
            if (!defineOnly)
            {
                outputString += string.Format("</defs>\n" +
                                              "<use xlink:href=\"#{0}\" x='0' y='0' style=\"fill:#000000;fill-opacity:1;stroke:none\" />\n" +
                                              "\n</svg>\n", idString);
            }

            return(outputString);
        }
Exemple #9
0
 private static byte[] GetRawDataAndSetEncoding(string code, DmtxImageEncoderOptions options, DmtxEncode encode)
 {
     byte[] result = Encoding.ASCII.GetBytes(code);
     encode.Scheme = options.Scheme;
     if (options.Scheme == DmtxScheme.DmtxSchemeAsciiGS1)
     {
         List <byte> prefixedRawData = new List <byte>(new[] { (byte)232 });
         prefixedRawData.AddRange(result);
         result        = prefixedRawData.ToArray();
         encode.Scheme = DmtxScheme.DmtxSchemeAscii;
     }
     return(result);
 }
 public string EncodeSvgImage(string val, DmtxImageEncoderOptions options)
 {
     DmtxEncode encode = new DmtxEncode();
     encode.ModuleSize = options.ModuleSize;
     encode.MarginSize = options.MarginSize;
     encode.SizeIdxRequest = options.SizeIdx;
     encode.Scheme = options.Scheme;
     byte[] valAsByteArray = Encoding.ASCII.GetBytes(val);
     encode.EncodeDataMatrix(options.ForeColor, options.BackColor, valAsByteArray);
     return EncodeSvgFile(encode, "", options.ModuleSize, options.MarginSize, options.ForeColor, options.BackColor);
 }
 private Bitmap EncodeImage(string val, DmtxImageEncoderOptions options, bool isMosaic)
 {
     DmtxEncode encode = new DmtxEncode();
     encode.ModuleSize = options.ModuleSize;
     encode.MarginSize = options.MarginSize;
     encode.Scheme = options.Scheme;
     encode.SizeIdxRequest = options.SizeIdx;
     byte[] valAsByteArray = Encoding.ASCII.GetBytes(val);
     if (isMosaic)
     {
         encode.EncodeDataMosaic(valAsByteArray);
     }
     else
     {
         encode.EncodeDataMatrix(options.ForeColor, options.BackColor, valAsByteArray);
     }
     return CopyDataToBitmap(encode.Image.Pxl, encode.Image.Width, encode.Image.Height);
 }
        internal string EncodeSvgFile(DmtxEncode enc, string format, int moduleSize, int margin, Color foreColor, Color backColor)
        {
            int col, row, rowInv;
            int symbolCols, symbolRows;
            int width, height, module;
            bool defineOnly = false;
            //byte mosaicRed, mosaicGrn, mosaicBlu;
            string idString = null;
            string style = "";
            string outputString = "";

            if (dotFormatProvider == null)
            {
                dotFormatProvider = new NumberFormatInfo();
                dotFormatProvider.NumberDecimalSeparator = ".";
            }

            if (format == "svg:")
            {
                defineOnly = true;
                idString = format.Substring(4);
            }

            if (string.IsNullOrEmpty(idString))
            {
                idString = "dmtx_0001";
            }

            width = 2 * enc.MarginSize + (enc.Region.SymbolCols * enc.ModuleSize);
            height = 2 * enc.MarginSize + (enc.Region.SymbolRows * enc.ModuleSize);

            symbolCols = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolCols, enc.Region.SizeIdx);
            symbolRows = DmtxCommon.GetSymbolAttribute(DmtxSymAttribute.DmtxSymAttribSymbolRows, enc.Region.SizeIdx);

            /* Print SVG Header */
            if (!defineOnly)
            {
                outputString += string.Format(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
                    "<!-- Created with DataMatrix (http://datamatrixnet.sourceforge.net/) -->\n" +
              "<svg\n" +
             "xmlns:svg=\"http://www.w3.org/2000/svg\"\n" +
             "xmlns=\"http://www.w3.org/2000/svg\"\n" +
             "xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n" +
             "version=\"1.0\"\n" +
             "width=\"{0}\"\n" +
             "height=\"{1}\"\n" +
             "id=\"svg2\">\n" +
            "<defs>\n" +
            "<symbol id=\"{2}\">\n" +
                 "    <desc>Layout:{0}x%{1} Symbol:{3}x{4} Data Matrix</desc>\n", width, height, idString, symbolCols, symbolRows);
            }

            if (backColor != Color.White)
            {
                style = string.Format("style=\"fill:#{0}{1}{2};fill-opacity:{3};stroke:none\" ",
                              backColor.R.ToString("X2"), backColor.G.ToString("X2"), backColor.B.ToString("X2"), ((double)backColor.A / (double)byte.MaxValue).ToString("0.##", dotFormatProvider));
                outputString += string.Format("    <rect width=\"{0}\" height=\"{1}\" x=\"0\" y=\"0\" {2}/>\n",
                      width, height, style);
                style = "";
            }

            /* Write Data Matrix ON modules */
            for (row = 0; row < enc.Region.SymbolRows; row++)
            {
                rowInv = enc.Region.SymbolRows - row - 1;
                for (col = 0; col < enc.Region.SymbolCols; col++)
                {
                    module = enc.Message.SymbolModuleStatus(enc.Region.SizeIdx, row, col);
                    style = string.Format("style=\"fill:#{0}{1}{2};fill-opacity:{3};stroke:none\" ",
                          foreColor.R.ToString("X2"), foreColor.G.ToString("X2"), foreColor.B.ToString("X2"), ((double)foreColor.A / (double)byte.MaxValue).ToString("0.##", dotFormatProvider));

                    if ((module & DmtxConstants.DmtxModuleOn) != 0)
                    {
                        outputString += string.Format("    <rect width=\"{0}\" height=\"{1}\" x=\"{2}\" y=\"{3}\" {4}/>\n",
                              moduleSize, moduleSize,
                              col * moduleSize + margin,
                              rowInv * moduleSize + margin, style);
                    }
                }
            }

            outputString += "  </symbol>\n";

            /* Close SVG document */
            if (!defineOnly)
            {
                outputString += string.Format("</defs>\n" +
            "<use xlink:href=\"#{0}\" x='0' y='0' style=\"fill:#000000;fill-opacity:1;stroke:none\" />\n" +
              "\n</svg>\n", idString);
            }

            return outputString;
        }