private void DrawingContent(QrCodeCustom qrCodeCustom, EncoderOptions options)
        {
            List <QrBitmapMatrix> matrixs = options.BitMats.FindAll(f => f.Tag == qrCodeCustom.QrCodeTag);

            int offsetmudule = 1;
            int ModuleSize   = MudelSize / 7;

            for (int i = 0; i < matrixs.Count; i++)
            {
                int rowX    = matrixs[i].Point.X * ModuleSize;
                int columnY = matrixs[i].Point.Y * ModuleSize;

                if (matrixs[i].BoolVar)
                {
                    GraphicsCustom.FillRectangle(Brushes.Black, new Rectangle(rowX, columnY, ModuleSize, ModuleSize));
                    // GraphicsCustom.FillEllipse(new SolidBrush(qrCodeCustom.ColorBrush), new Rectangle(rowX, columnY, offset, offset));
                    GraphicsCustom.Flush();
                }
                //else
                //{
                //    GraphicsCustom.FillEllipse(Brushes.White, new Rectangle(rowX, columnY, offset, offset));
                //    GraphicsCustom.Flush();
                //    int b = Bitmap.GetPixel(rowX, columnY).B;
                //    int g = Bitmap.GetPixel(rowX, columnY).G;
                //    int r = Bitmap.GetPixel(rowX, columnY).R;
                //    int rgb = (b + g + r) / 3;
                //    if (rgb < 128)
                //    {
                //        GraphicsCustom.FillEllipse(Brushes.White, new Rectangle(rowX, columnY, offset, offset));
                //        GraphicsCustom.Flush();
                //    }
                //}
            }
        }
        public Bitmap DrawQrCode(EncoderOptions options)
        {
            SetImg(options.LogoImgPath);
            var QrCodeMinWidth = options.Matrix.Width * MudelSize / 7;

            Bitmap         = new Bitmap(QrCodeMinWidth, QrCodeMinWidth, PixelFormat.Format24bppRgb);
            GraphicsCustom = Graphics.FromImage(Bitmap);
            GraphicsCustom.Clear(Color.White);
            GraphicsCustom.Flush();

            // graphics.Dispose();

            for (int i = 0; i < options.QrCodeCustoms.Count; i++)
            {
                QrCodeCustom qrCodeCustom = options.QrCodeCustoms[i];
                if (qrCodeCustom.QrCodeTag != Tag.Content)
                {
                    DrawTag(qrCodeCustom, options);
                }
                else
                {
                    DrawingContent(qrCodeCustom, options);
                }
            }
            GraphicsCustom.Flush();
            GraphicsCustom.Dispose();
            return(Bitmap);
        }
        public void QrCodeTagOneCommand(QrCodeCustom qrCodeCustom)
        {
            int index = QrCodeCustoms.FindIndex(f => f.QrCodeTag == qrCodeCustom.QrCodeTag);

            if (index >= 0)
            {
                QrCodeCustoms[index] = qrCodeCustom;
                // EnQrCode();
            }
        }
        private void DrawTagCircle(QrCodeCustom custom, List <QrBitmapMatrix> qrBitmaps)
        {
            List <QrBitmapMatrix> matrices = qrBitmaps.FindAll(f => f.Tag == custom.QrCodeTag);

            if (matrices.Count > 0)
            {
                Rectangle rect = matrices[0].Rectangle;

                Rectangle Ellipserect = new Rectangle()
                {
                    X      = rect.X,
                    Y      = rect.Y,
                    Width  = rect.Width * 7,
                    Height = rect.Height * 7
                };
                Rectangle Ellipserect2 = new Rectangle()
                {
                    X      = rect.X + rect.Width,
                    Y      = rect.Y + rect.Width,
                    Width  = rect.Width * 5,
                    Height = rect.Height * 5
                };
                Rectangle Ellipserect3 = new Rectangle()
                {
                    X      = rect.X + rect.Width * 2,
                    Y      = rect.Y + rect.Width * 2,
                    Width  = rect.Width * 3,
                    Height = rect.Height * 3
                };
                for (int i = 0; i < 3; i++)
                {
                    if (i == 0)
                    {
                        GraphicsCustom.FillEllipse(new SolidBrush(custom.ColorBrush), Ellipserect);
                    }
                    if (i == 1)
                    {
                        GraphicsCustom.FillEllipse(Brushes.White, Ellipserect2);
                    }
                    if (i == 2)
                    {
                        GraphicsCustom.FillEllipse(new SolidBrush(custom.ColorBrush), Ellipserect3);
                    }
                }
            }

            GraphicsCustom.Flush();
            // graphics.Dispose();
        }
        private void DrawingContent(QrCodeCustom custom, EncoderOptions options)
        {
            List <QrBitmapMatrix> matrixs = options.BitMats.FindAll(f => f.Tag == custom.QrCodeTag);

            int offset       = 1;
            int offsetmudule = 1;
            int ModuleSize   = matrixs[0].Rectangle.Width;

            if (custom.QrCodeSize == QrCodeSquareSize.Max)
            {
                offset       = ModuleSize / 2;
                offsetmudule = offset / 2;
            }
            if (custom.QrCodeSize == QrCodeSquareSize.Min)
            {
                offset       = ModuleSize / 3;
                offsetmudule = offset;
            }
            // Graphics graphics = Graphics.FromImage(bitmap);
            for (int i = 0; i < matrixs.Count; i++)
            {
                int rowX    = matrixs[i].Rectangle.X + offsetmudule;
                int columnY = matrixs[i].Rectangle.Y + offsetmudule;

                if (matrixs[i].BoolVar)
                {
                    GraphicsCustom.FillEllipse(new SolidBrush(custom.ColorBrush), new Rectangle(rowX, columnY, offset, offset));
                    GraphicsCustom.Flush();
                }
                else
                {
                    GraphicsCustom.FillEllipse(Brushes.White, new Rectangle(rowX, columnY, offset, offset));
                    GraphicsCustom.Flush();
                    //int b = Bitmap.GetPixel(rowX, columnY).B;
                    //int g = Bitmap.GetPixel(rowX, columnY).G;
                    //int r = Bitmap.GetPixel(rowX, columnY).R;
                    //int rgb = (b + g + r) / 3;
                    //if (rgb < 128)
                    //{
                    //    GraphicsCustom.FillEllipse(Brushes.White, new Rectangle(rowX, columnY, offset, offset));
                    //    GraphicsCustom.Flush();

                    //}
                }
            }
            GraphicsCustom.Flush();
            GraphicsCustom.Dispose();
        }
        private void DrawTag(QrCodeCustom qrCodeCustom, EncoderOptions options)
        {
            List <QrBitmapMatrix> matrixs = options.BitMats.FindAll(f => f.Tag == qrCodeCustom.QrCodeTag);// qrCodeCustom.QrCodeTag

            int ModuleSize = MudelSize / 7;

            int    rowX    = matrixs[0].Point.X * ModuleSize;
            int    columnY = matrixs[0].Point.Y * ModuleSize;
            Bitmap bitmap  = GetTagImg(options.LogoImgPath, qrCodeCustom.QrCodeTag);

            bitmap = OtsuThreshold(bitmap).ToBitmap();
            //bitmap.Save(@"D:\Desktop\DIYcode\bitmap212313123123.jpg");

            GraphicsCustom.DrawImage(bitmap, rowX, columnY, Rectangles[0].Width, Rectangles[0].Height);

            // throw new NotImplementedException();
        }
 private void DrawTagSquare(QrCodeCustom custom, List <QrBitmapMatrix> qrBitmapMatrices)
 {
     if (qrBitmapMatrices.Count > 0)
     {
         for (int i = 0; i < qrBitmapMatrices.Count; i++)
         {
             Rectangle rect = qrBitmapMatrices[i].Rectangle;
             if (qrBitmapMatrices[i].BoolVar)
             {
                 GraphicsCustom.FillRectangle(new SolidBrush(custom.ColorBrush), rect);
             }
             else
             {
                 GraphicsCustom.FillRectangle(Brushes.White, rect);
             }
         }
         GraphicsCustom.Flush();
     }
 }
        private void DrawTag(QrCodeCustom custom, EncoderOptions options)
        {
            List <QrBitmapMatrix> matrices = options.BitMats.FindAll(f => f.Tag == custom.QrCodeTag);

            //int ModuleSize = options.QrRect.ModuleSize;
            //int QuietZoneModuleSize = (int)options.QrRect.ZoneModule * ModuleSize;
            switch (custom.QrCodeStyle)
            {
            case QrCodeStyleEnum.Square:
                DrawTagSquare(custom, matrices);
                break;

            case QrCodeStyleEnum.Circle:
                DrawTagCircle(custom, matrices);
                break;

            case QrCodeStyleEnum.Excircle:
                DrawTagExcircle(custom, matrices);

                break;

            case QrCodeStyleEnum.InnerCircle:
                DrawTagInnerCircle(custom, matrices);
                break;

            case QrCodeStyleEnum.ExInnerCircle:
                DrawTagExInnercircle(custom, matrices);
                break;

            case QrCodeStyleEnum.ExSquareCircle:
                DrawTagExSquareCircle(custom, matrices);
                break;

            //case QrCodeStyleEnum.CustomSquare:
            //    DrawTagCustomSquare(custom, matrices);
            //    break;

            default:
                break;
            }
        }
        public Bitmap DrawQrCode(EncoderOptions options)
        {
            Bitmap logoimg = GetLogoBitmap(options);

            Bitmap         = new Bitmap(options.QrRect.QrCodeMinWidth, options.QrRect.QrCodeMinWidth, PixelFormat.Format24bppRgb);
            GraphicsCustom = Graphics.FromImage(Bitmap);
            GraphicsCustom.Clear(Color.White);

            if (options.IsTopLogoImg)
            {
                // Bitmap = new Bitmap(logoimg.Width, logoimg.Height, PixelFormat.Format24bppRgb);
                if (logoimg != null)
                {
                    GraphicsCustom.DrawImage(logoimg, 0, 0, logoimg.Width, logoimg.Height);
                }
            }
            else
            {
                if (logoimg != null)
                {
                    int pointx = (int)(Bitmap.Width / 2 - logoimg.Width / 2);
                    int pointy = (int)(Bitmap.Height / 2 - logoimg.Height / 2);

                    GraphicsCustom.DrawImage(logoimg, pointx, pointy, logoimg.Width, logoimg.Height);
                }
            }
            GraphicsCustom.Flush();
            for (int i = 0; i < options.QrCodeCustoms.Count; i++)
            {
                QrCodeCustom qrCodeCustom = options.QrCodeCustoms[i];
                if (qrCodeCustom.QrCodeTag != Tag.Content)
                {
                    DrawTag(qrCodeCustom, options);
                }
                else
                {
                    DrawingContent(qrCodeCustom, options);
                }
            }
            return(Bitmap);
        }
 private void DrawTagCustomSquare(QrCodeCustom custom, List <QrBitmapMatrix> matrices)
 {
     throw new NotImplementedException();
 }