public override Bitmap Encode(string content) { try { this.matrix = QrCodeEncoder.calQrcode(EnCoding.GetBytes(content)); } catch { throw new Exception("内容超出范围,请选择更高版本或者降低容错率"); } this.SetParam(); //SolidBrush Backbrush = new SolidBrush(QrCodeEncoder.QRCodeBackgroundColor); SolidBrush Backbrush = new SolidBrush(Color.Transparent);//背景透明 SolidBrush Forebrush = new SolidBrush(QrCodeEncoder.QRCodeForegroundColor); Bitmap image = new Bitmap(this.QrCodeW, this.QrCodeH); Graphics g = Graphics.FromImage(image); g.DrawImage(_imgSky, 0, 0, image.Width, image.Height);//后背景 Rectangle rect = new Rectangle(); g.FillRectangle(Backbrush, new Rectangle(0, 0, image.Width, image.Height)); FillShape _FillShape = new FillShape(); for (int i = 0; i < matrix.Length; i++) { for (int j = 0; j < matrix.Length; j++) { rect = new Rectangle((j + this.SpacingW) * QrCodeEncoder.QRCodeScale, (i + this.SpacingH) * QrCodeEncoder.QRCodeScale, QrCodeEncoder.QRCodeScale, QrCodeEncoder.QRCodeScale); if (matrix[j][i]) { rect = ChangeSuperMario(matrix, Backbrush, Forebrush, g, rect, i, j); } else { this.ChangeFillShape(g, Backbrush, rect, EN_FillShape.FillEllipse, new FillShape(), Backbrush); } } } return(image); }
public override Bitmap Encode(string content) { try { this.matrix = QrCodeEncoder.calQrcode(EnCoding.GetBytes(content)); } catch { throw new Exception("内容超出范围,请选择更高版本或者降低容错率"); } this.SetParam(); //SolidBrush Backbrush = new SolidBrush(QrCodeEncoder.QRCodeBackgroundColor); SolidBrush Backbrush = new SolidBrush(Color.Transparent);//背景透明 SolidBrush Forebrush = new SolidBrush(QrCodeEncoder.QRCodeForegroundColor); Bitmap image = new Bitmap(this.QrCodeW, this.QrCodeH); Graphics g = Graphics.FromImage(image); g.DrawImage(_imgSky, 0, 0, image.Width, image.Height);//后背景 Rectangle rect = new Rectangle(); g.FillRectangle(Backbrush, new Rectangle(0, 0, image.Width, image.Height)); FillShape _FillShape = new FillShape(); for (int i = 0; i < matrix.Length; i++) { for (int j = 0; j < matrix.Length; j++) { rect = new Rectangle((j + this.SpacingW) * QrCodeEncoder.QRCodeScale, (i + this.SpacingH) * QrCodeEncoder.QRCodeScale, QrCodeEncoder.QRCodeScale, QrCodeEncoder.QRCodeScale); if (matrix[j][i]) { rect = ChangeSuperMario(matrix, Backbrush, Forebrush, g, rect, i, j); } else { this.ChangeFillShape(g, Backbrush, rect, EN_FillShape.FillEllipse, new FillShape(), Backbrush); } } } return image; }