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("内容超出范围,请选择更高版本或者降低容错率"); } QrCodeEncoder.FrameSpacingH = 4; QrCodeEncoder.FrameSpacingW = 6 * QrCodeEncoder.QRCodeVersion; 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); Rectangle rect = new Rectangle(); g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, image.Width, image.Height)); int _spanCount = 0; 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]) { ChangeAngry_Birds(matrix, Backbrush, Forebrush, g, ref rect, ref _spanCount, i, j); this.ChangeFixedShape(EN_FixedShape.Fixed1, g, new SolidBrush(Color.White), rect, EN_FillShape.FillRectangle, new FillShape(), Backbrush, j, i); this.ChangeFixedShape(EN_FixedShape.Fixed2, g, new SolidBrush(Color.White), rect, EN_FillShape.FillRectangle, new FillShape(), Backbrush, j, i); this.ChangeFixedShape(EN_FixedShape.Fixed3, g, new SolidBrush(Color.White), rect, EN_FillShape.FillRectangle, new FillShape(), Backbrush, j, i); } else { this.ChangeFillShape(g, Backbrush, rect, EN_FillShape.FillRectangle, new FillShape(), Backbrush); } } } //计算比例 //float _grassScale = Convert.ToSingle(QrCodeEncoder.QRCodeScale) / Convert.ToSingle(this.QrCodeH); float _grassScaleH = this.QrCodeH / 10 * 2; float _grassScaleW = this.QrCodeW / 6 * 2; g.DrawImage(_imggrass, 0, this.QrCodeH - _grassScaleH, _grassScaleW, _grassScaleH); int _addImgGrassCount = AddimgGrassCount((rect.Location.X + this.SpacingW) * QrCodeEncoder.QRCodeScale, Convert.ToInt32(_grassScaleW)); for (int i = 1; i < _addImgGrassCount; i++) { g.DrawImage(_imggrass2, i * _grassScaleW, this.QrCodeH - _grassScaleH, _grassScaleW, _grassScaleH); } this.ChangeFixedShape(new SolidBrush(Color.White), Forebrush, g, EN_FixedShape.Fixed1, EN_FillShape.DrawImage, new FillShape() { img = _imgfixedShape1 }, true); this.ChangeFixedShape(new SolidBrush(Color.White), Forebrush, g, EN_FixedShape.Fixed2, EN_FillShape.DrawImage, new FillShape() { img = _imgfixedShape1 }, true); this.ChangeFixedShape(new SolidBrush(Color.White), Forebrush, g, EN_FixedShape.Fixed3, EN_FillShape.DrawImage, new FillShape() { img = _imgfixedShape1 }, true); this.ChangeFixedShape(new SolidBrush(Color.White), Forebrush, g, EN_FixedShape.Fixed1_0, EN_FillShape.DrawImage, new FillShape() { img = _imgfixedShape2_0 }, true); this.ChangeFixedShape(new SolidBrush(Color.White), Forebrush, g, EN_FixedShape.Fixed2_0, EN_FillShape.DrawImage, new FillShape() { img = _imgfixedShape2_0 }, true); this.ChangeFixedShape(new SolidBrush(Color.White), Forebrush, g, EN_FixedShape.Fixed3_0, EN_FillShape.DrawImage, new FillShape() { img = _imgfixedShape2_0 }, true); return(image); }