qrcodenet二维码图片下扩展区域添加号段的操作

总监安排了个任务,一个号码导出一个二维码图, 我实现了最终还能批量生成,结果主管说要在图片下边添加一行,和图片是一起的

最开始把控件的上的图给改了,结果保存起来没用,控件上的图跟要保存的不是一个事。

最终找到在此方法中修改:

程序是先绘制背景图。

然后,把二维码的矩阵,小模块一个个打印出来。

把y点的padding 数去掉,生成的图片就会升到背景图的顶部,觉得太靠顶了自己加个参数。

Point modulePosition = new Point(preX * size.ModuleSize + padding + offset.X,
                                y * size.ModuleSize + offset.Y);
Point modulePosition = new Point(preX * size.ModuleSize + padding + offset.X,
                            y * size.ModuleSize  + offset.Y);
 
   public void Draw(Graphics graphics, BitMatrix QrMatrix, Point offset)
        {
            int width = QrMatrix == null ? 21 : QrMatrix.Width;

            DrawingSize size = m_iSize.GetSize(width);
            //绘背景图图
            graphics.FillRectangle(m_LightBrush, offset.X, offset.Y, size.CodeWidth, size.CodeWidth);

            if(QrMatrix == null || size.ModuleSize == 0)
                return;

            int padding = (size.CodeWidth - (size.ModuleSize * width)) / 2;

            int preX = -1;

            for (int y = 0; y < width; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (QrMatrix[x, y])
                    {
                        //Set start point if preX == -1
                        if (preX == -1)
                            preX = x;
                        //If this is last module in that row. Draw rectangle
                        if (x == width - 1)
                        {
                            Point modulePosition = new Point(preX * size.ModuleSize + padding + offset.X,
                                y * size.ModuleSize + offset.Y);
                            Size rectSize = new Size((x - preX + 1) * size.ModuleSize, size.ModuleSize);
                            graphics.FillRectangle(m_DarkBrush, modulePosition.X, modulePosition.Y, rectSize.Width, rectSize.Height);
                            preX = -1;
                        }
                    }
                    else if (!QrMatrix[x, y] && preX != -1)
                    {
                        //Here will be first light module after sequence of dark module.
                        //Draw previews sequence of dark Module
                        Point modulePosition = new Point(preX * size.ModuleSize + padding + offset.X,
                            y * size.ModuleSize  + offset.Y);
                        Size rectSize = new Size((x - preX) * size.ModuleSize, size.ModuleSize);
                        graphics.FillRectangle(m_DarkBrush, modulePosition.X, modulePosition.Y, rectSize.Width, rectSize.Height);
                        preX = -1;
                    }
                }
            }
         
        }

 

原文地址:https://www.cnblogs.com/zuochanzi/p/5980937.html