예제 #1
0
        public virtual IImage Create(string data, IRgb24BitmapBase image)
        {
            var bitMatrix = QRCodeEncoder.Build(data);

            if (image != null)
            {
                int moduleCount = bitMatrix.Size;
                var imgMatrix   = Binarizer.Binarize(image, moduleCount * 3, moduleCount * 3);
                bitMatrix = Merger.Merge(bitMatrix, QRCodeEncoder.TypeNumber, imgMatrix);
            }
            return(BitMatrixDrawer.Draw(bitMatrix));
        }
예제 #2
0
        public virtual IImage Create(string data, IRgb24BitmapBase image, IRgb24BitmapBase imageText)
        {
            var bitMatrix = QRCodeEncoder.Build(data); //~20 ms



            if (image != null && 2 == 3) //qr code
            {
                int moduleCount    = bitMatrix.Size;
                var imgBitMatrix   = Binarizer.Binarize(image, moduleCount * 3, moduleCount * 3);
                var imgColorMatrix = Colorizer.Colorize(image, moduleCount * 3, moduleCount * 3);
                //var imgColorMatrix = new ColorSquare(moduleCount * 3);
                bitMatrix = Merger.Merge(bitMatrix, QRCodeEncoder.TypeNumber, imgBitMatrix);
                return(BitMatrixDrawer.Draw(bitMatrix, imgColorMatrix));
            }
            else if (image != null) //text on image
            {
                int moduleCount    = bitMatrix.Size;
                var imgColorMatrix = Colorizer.Colorize(image, moduleCount * 3, moduleCount * 3);
                var tripMatrix     = new TripSquare(500);

                for (var i = 0; i < 500; i++)
                {
                    for (var ii = 0; ii < 500; ii++)
                    {
                        tripMatrix[i, ii] = 0;
                    }
                }//~20 ms since else if



                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                for (var i = 5; i < 495; i++)
                {
                    for (var ii = 5; ii < 495; ii++)
                    {
                        if (imageText.GetPixel(i, ii) < 12000000)
                        {
                            tripMatrix[ii, i] = 1;
                        }
                        if (imageText.GetPixel(i, ii) < 8000000)
                        {
                            tripMatrix[ii, i] = 2;
                        }
                        if (imageText.GetPixel(i, ii) < 4000000)
                        {
                            tripMatrix[ii, i] = 3;
                        }
                    }
                }//~110 ms for this double loop



                for (var i = 10; i < 500 - 10; i++)
                {
                    for (var ii = 10; ii < 500 - 10; ii++)
                    {
                        /*
                         * if (tripMatrix[i,ii] == 0){
                         *      var minDist = 999;
                         *      for (var iii=i-10;iii<i+11;iii++){
                         *                              for (var iiii=ii-10;iiii<ii+11;iiii++){
                         *                                      if (tripMatrix[iii,iiii] > 0){
                         *                                              var d = (i-iii)*(i-iii)+(ii-iiii)*(ii-iiii);
                         *                                              if (d< minDist){
                         *                                                      minDist = d;
                         *                                              }
                         *                                      }
                         *                              }
                         *                      }
                         *                      if (minDist < 51){
                         *                              tripMatrix[i,ii] = (2*minDist-150)/5;
                         *                      }
                         * }
                         */

                        if (tripMatrix[i, ii] > 0)
                        {
                            for (var iii = i - 10; iii < i + 11; iii++)
                            {
                                for (var iiii = ii - 10; iiii < ii + 11; iiii++)
                                {
                                    if (tripMatrix[iii, iiii] == 0)
                                    {
                                        var d = (i - iii) * (i - iii) + (ii - iiii) * (ii - iiii);
                                        if (d < 51)
                                        {
                                            tripMatrix[iii, iiii] = (2 * d - 150) / 5;
                                        }
                                    }
                                    else if (tripMatrix[iii, iiii] < 0)
                                    {
                                        var d = (i - iii) * (i - iii) + (ii - iiii) * (ii - iiii);
                                        if (d < 51)
                                        {
                                            var dd = (2 * d - 150) / 5;
                                            if (dd < tripMatrix[iii, iiii])
                                            {
                                                tripMatrix[iii, iiii] = dd;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                stopWatch.Stop();
                // Get the elapsed time as a TimeSpan value.
                TimeSpan ts = stopWatch.Elapsed;

                // Format and display the TimeSpan value.
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                   ts.Hours, ts.Minutes, ts.Seconds,
                                                   ts.Milliseconds / 10);
                Console.WriteLine("QRArtCreatorTime " + elapsedTime);


                return(TripMatrixDrawer.Draw(tripMatrix, imgColorMatrix));
            }
            else
            {
                Console.Out.WriteLine("no image");
                var imgMatrix = new ColorSquare(bitMatrix.Size * 3);
                return(BitMatrixDrawer.Draw(bitMatrix, imgMatrix));
            }
        }