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); }
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(); }